From a331b87caa2ce4f3f664cdba8aef77e07055fe50 Mon Sep 17 00:00:00 2001 From: Wilson Li Date: Fri, 20 Oct 2017 11:45:13 +0900 Subject: [PATCH] Update to README about custom rotator and hour specification --- README.md | 44 ++++++++++++++++++++++++++++++++++++++ src/lager_file_backend.erl | 4 ++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5858a8f..1376846 100644 --- a/README.md +++ b/README.md @@ -521,6 +521,22 @@ Some examples: 6:00 hr ``` +On top of the day, week and month time format from newsyslog, +hour specification is added from PR [#420](https://github.com/erlang-lager/lager/pull/420) + +``` +Format of hour specification is : [Hmm] +The range for minute specification is: + + mm minutes, range 0 ... 59 + +Some examples: + + $H00 rotate every hour at HH:00 + $D12H30 rotate every day at 12:30 + $W0D0H0 rotate every week on Sunday at 00:00 +``` + To configure the crash log rotation, the following application variables are used: * `crash_log_size` @@ -529,6 +545,34 @@ used: See the `.app.src` file for further details. +Custom Log Rotation +------------------- +Custom log rotator could be configured with option for `lager_file_backend` +```erlang +{rotator, lager_util} +``` + +The module should provide the following callbacks as `lager_rotator_behaviour` + +```erlang +%% @doc Create a log file +-callback(create_logfile(Name::list(), Buffer::{integer(), integer()} | any()) -> + {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}). + +%% @doc Open a log file +-callback(open_logfile(Name::list(), Buffer::{integer(), integer()} | any()) -> + {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}). + +%% @doc Ensure reference to current target, could be rotated +-callback(ensure_logfile(Name::list(), FD::file:io_device(), Inode::integer(), + Buffer::{integer(), integer()} | any()) -> + {ok, {FD::file:io_device(), Inode::integer(), Size::integer()}} | {error, any()}). + +%% @doc Rotate the log file +-callback(rotate_logfile(Name::list(), Count::integer()) -> + ok). +``` + Syslog Support -------------- Lager syslog output is provided as a separate application: diff --git a/src/lager_file_backend.erl b/src/lager_file_backend.erl index c6f031d..e606fd7 100644 --- a/src/lager_file_backend.erl +++ b/src/lager_file_backend.erl @@ -111,8 +111,8 @@ init(LogFileConfig) when is_list(LogFileConfig) -> {error, {fatal, bad_config}}; Config -> %% probabably a better way to do this, but whatever - [RelName, Level, Date, Size, Count, Rotator, HighWaterMark, SyncInterval, SyncSize, SyncOn, CheckInterval, Formatter, FormatterConfig] = - [proplists:get_value(Key, Config) || Key <- [file, level, date, size, count, rotator, high_water_mark, sync_interval, sync_size, sync_on, check_interval, formatter, formatter_config]], + [RelName, Level, Date, Size, Count, Rotator, HighWaterMark, Flush, SyncInterval, SyncSize, SyncOn, CheckInterval, Formatter, FormatterConfig] = + [proplists:get_value(Key, Config) || Key <- [file, level, date, size, count, rotator, high_water_mark, flush_queue, sync_interval, sync_size, sync_on, check_interval, formatter, formatter_config]], FlushThr = proplists:get_value(flush_threshold, Config, 0), Name = lager_util:expand_path(RelName), schedule_rotation(Name, Date),