-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit creates a new module called `ar_logger` where all functions related to logging are present. The goal here is also to get rid of the `disk_log` logging type causing sync issues on rsyslog and using a more conventional "Unix way" to store logs. The previous method using `disk_log` was using a wrap method, creating also two files ending with .siz and .idx to follow the logs. One of the important feature of `disk_log` is to repair logs, but it seems this feature is not used. Instead, using a simple append method with `logger_std_h` mode will make things easier when collecting logs.
- Loading branch information
Showing
2 changed files
with
87 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
%%%=================================================================== | ||
%%% @doc module in charge of the logging features. | ||
%%% @end | ||
%%%=================================================================== | ||
-module(ar_logger). | ||
-export([init/1]). | ||
-include_lib("arweave/include/ar.hrl"). | ||
-include_lib("arweave/include/ar_config.hrl"). | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @doc Uses #config{} record by default. | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
init(Config) -> | ||
init_console(Config), | ||
init_default(Config), | ||
init_debug(Config). | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @hidden | ||
%% @doc Configure logging for console output. | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
init_console(Config) -> | ||
Template = [time," [",level,"] ",mfa,":",line," ",msg,"\n"], | ||
LoggerFormatterConsole = #{ legacy_header => false | ||
, single_line => true | ||
, chars_limit => 16256 | ||
, max_size => 8128 | ||
, depth => 256 | ||
, template => Template | ||
}, | ||
logger:set_handler_config(default, formatter, {logger_formatter, LoggerFormatterConsole}), | ||
logger:set_handler_config(default, level, error). | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @hidden | ||
%% @doc Configure logging to the logfile. | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
init_default(Config) -> | ||
Level = info, | ||
FileName = "arweave.log", | ||
FilePath = lists:flatten(filename:join(Config#config.log_dir, FileName)), | ||
LoggerConfigDisk = #{ file => FilePath | ||
, type => file | ||
, max_no_files => 10 | ||
, max_no_bytes => 51418800 % 10 x 5MB | ||
, modes => [raw, append] | ||
}, | ||
LoggerConfig = #{ config => LoggerConfigDisk, level => Level }, | ||
Template = [time," [",level,"] ",mfa,":",line," ",msg,"\n"], | ||
LoggerFormatterDisk = #{ chars_limit => 16256 | ||
, max_size => 8128 | ||
, depth => 256 | ||
, legacy_header => false | ||
, single_line => true | ||
, template => Template | ||
}, | ||
logger:add_handler(disk_log, logger_std_h, LoggerConfig), | ||
logger:set_handler_config(disk_log, formatter, {logger_formatter, LoggerFormatterDisk}). | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @hidden | ||
%% @doc set debug logging feature | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
init_debug(#config{ debug = true } = Config) -> | ||
Level = debug, | ||
FileName = "debug.log", | ||
FilePath = lists:flatten(filename:join([Config#config.log_dir, "debug.log"])), | ||
DebugLoggerConfigDisk = #{ file => FilePath | ||
, type => file | ||
, max_no_files => 20 | ||
, max_no_bytes => 51418800 % 10 x 5MB | ||
, modes => [raw, append] | ||
}, | ||
LoggerConfig = #{ config => DebugLoggerConfigDisk, level => Level }, | ||
logger:add_handler(disk_debug_log, logger_std_h, LoggerConfig), | ||
logger:set_application_level(arweave, Level); | ||
init_debug(_) -> | ||
Level = info, | ||
logger:set_application_level(arweave, Level). | ||
|