2013-04-08 11:12:54 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
2017-01-03 15:58:52 +01:00
|
|
|
%%% File : ejabberd_logger.erl
|
|
|
|
%%% Author : Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
|
|
|
%%% Purpose : ejabberd logger wrapper
|
2013-04-08 11:12:54 +02:00
|
|
|
%%% Created : 12 May 2013 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
2013-06-18 16:56:29 +02:00
|
|
|
%%%
|
2017-01-03 15:58:52 +01:00
|
|
|
%%%
|
2021-01-27 16:55:25 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2013-2021 ProcessOne
|
2013-06-18 16:56:29 +02:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2013-06-18 16:56:29 +02:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
-module(ejabberd_logger).
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
-compile({no_auto_import, [get/0]}).
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
%% API
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
-export([start/0, get/0, set/1, get_log_path/0, flush/0]).
|
|
|
|
-export([convert_loglevel/1, loglevels/0]).
|
2019-10-25 10:44:04 +02:00
|
|
|
-ifndef(LAGER).
|
2019-10-18 21:00:37 +02:00
|
|
|
-export([progress_filter/2]).
|
2019-10-25 10:44:04 +02:00
|
|
|
-endif.
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
%% Deprecated functions
|
|
|
|
-export([restart/0, reopen_log/0, rotate_log/0]).
|
|
|
|
-deprecated([{restart, 0},
|
|
|
|
{reopen_log, 0},
|
|
|
|
{rotate_log, 0}]).
|
2013-06-27 10:58:56 +02:00
|
|
|
|
2019-10-25 10:44:04 +02:00
|
|
|
-type loglevel() :: none | emergency | alert | critical |
|
|
|
|
error | warning | notice | info | debug.
|
2013-06-27 10:58:56 +02:00
|
|
|
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
-define(is_loglevel(L),
|
|
|
|
((L == none) or (L == emergency) or (L == alert)
|
|
|
|
or (L == critical) or (L == error) or (L == warning)
|
|
|
|
or (L == notice) or (L == info) or (L == debug))).
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2019-10-25 14:27:47 +02:00
|
|
|
-export_type([loglevel/0]).
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
-spec get_log_path() -> string().
|
2013-06-27 10:58:56 +02:00
|
|
|
get_log_path() ->
|
2015-04-06 11:36:16 +02:00
|
|
|
case ejabberd_config:env_binary_to_list(ejabberd, log_path) of
|
2013-06-27 10:58:56 +02:00
|
|
|
{ok, Path} ->
|
|
|
|
Path;
|
|
|
|
undefined ->
|
|
|
|
case os:getenv("EJABBERD_LOG_PATH") of
|
|
|
|
false ->
|
2018-06-14 13:00:47 +02:00
|
|
|
"ejabberd.log";
|
2013-06-27 10:58:56 +02:00
|
|
|
Path ->
|
|
|
|
Path
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
-spec loglevels() -> [loglevel(), ...].
|
|
|
|
loglevels() ->
|
|
|
|
[none, emergency, alert, critical, error, warning, notice, info, debug].
|
|
|
|
|
|
|
|
-spec convert_loglevel(0..5) -> loglevel().
|
|
|
|
convert_loglevel(0) -> none;
|
|
|
|
convert_loglevel(1) -> critical;
|
|
|
|
convert_loglevel(2) -> error;
|
|
|
|
convert_loglevel(3) -> warning;
|
|
|
|
convert_loglevel(4) -> info;
|
|
|
|
convert_loglevel(5) -> debug.
|
|
|
|
|
2021-01-27 09:24:05 +01:00
|
|
|
quiet_mode() ->
|
|
|
|
case application:get_env(ejabberd, quiet) of
|
|
|
|
{ok, true} -> true;
|
|
|
|
_ -> false
|
|
|
|
end.
|
|
|
|
|
2019-10-25 10:44:04 +02:00
|
|
|
-spec get_integer_env(atom(), T) -> T.
|
|
|
|
get_integer_env(Name, Default) ->
|
|
|
|
case application:get_env(ejabberd, Name) of
|
|
|
|
{ok, I} when is_integer(I), I>=0 ->
|
|
|
|
I;
|
2021-01-13 11:47:51 +01:00
|
|
|
{ok, infinity} ->
|
|
|
|
infinity;
|
2019-10-25 10:44:04 +02:00
|
|
|
undefined ->
|
|
|
|
Default;
|
|
|
|
{ok, Junk} ->
|
|
|
|
error_logger:error_msg("wrong value for ~ts: ~p; "
|
|
|
|
"using ~p as a fallback~n",
|
|
|
|
[Name, Junk, Default]),
|
|
|
|
Default
|
|
|
|
end.
|
|
|
|
|
|
|
|
-ifdef(LAGER).
|
|
|
|
-spec get_string_env(atom(), T) -> T.
|
|
|
|
get_string_env(Name, Default) ->
|
|
|
|
case application:get_env(ejabberd, Name) of
|
|
|
|
{ok, L} when is_list(L) ->
|
|
|
|
L;
|
|
|
|
undefined ->
|
|
|
|
Default;
|
|
|
|
{ok, Junk} ->
|
|
|
|
error_logger:error_msg("wrong value for ~ts: ~p; "
|
|
|
|
"using ~p as a fallback~n",
|
|
|
|
[Name, Junk, Default]),
|
|
|
|
Default
|
|
|
|
end.
|
|
|
|
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
-spec start() -> ok.
|
2013-04-08 11:12:54 +02:00
|
|
|
start() ->
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
start(info).
|
2017-12-17 19:03:40 +01:00
|
|
|
|
2019-10-25 10:44:04 +02:00
|
|
|
start(Level) ->
|
|
|
|
StartedApps = application:which_applications(5000),
|
|
|
|
case lists:keyfind(logger, 1, StartedApps) of
|
|
|
|
%% Elixir logger is started. We assume everything is in place
|
|
|
|
%% to use lager to Elixir logger bridge.
|
|
|
|
{logger, _, _} ->
|
|
|
|
error_logger:info_msg("Ignoring ejabberd logger options, using Elixir Logger.", []),
|
|
|
|
%% Do not start lager, we rely on Elixir Logger
|
|
|
|
do_start_for_logger(Level);
|
|
|
|
_ ->
|
|
|
|
do_start(Level)
|
|
|
|
end.
|
|
|
|
|
|
|
|
do_start_for_logger(Level) ->
|
|
|
|
application:load(sasl),
|
|
|
|
application:set_env(sasl, sasl_error_logger, false),
|
|
|
|
application:load(lager),
|
|
|
|
application:set_env(lager, error_logger_redirect, false),
|
|
|
|
application:set_env(lager, error_logger_whitelist, ['Elixir.Logger.ErrorHandler']),
|
|
|
|
application:set_env(lager, crash_log, false),
|
|
|
|
application:set_env(lager, handlers, [{elixir_logger_backend, [{level, Level}]}]),
|
|
|
|
ejabberd:start_app(lager),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
do_start(Level) ->
|
|
|
|
application:load(sasl),
|
|
|
|
application:set_env(sasl, sasl_error_logger, false),
|
|
|
|
application:load(lager),
|
|
|
|
ConsoleLog = get_log_path(),
|
|
|
|
Dir = filename:dirname(ConsoleLog),
|
|
|
|
ErrorLog = filename:join([Dir, "error.log"]),
|
|
|
|
CrashLog = filename:join([Dir, "crash.log"]),
|
|
|
|
LogRotateDate = get_string_env(log_rotate_date, ""),
|
2021-01-13 11:47:51 +01:00
|
|
|
LogRotateSize = case get_integer_env(log_rotate_size, 10*1024*1024) of
|
|
|
|
infinity -> 0;
|
|
|
|
V -> V
|
|
|
|
end,
|
2019-10-25 10:44:04 +02:00
|
|
|
LogRotateCount = get_integer_env(log_rotate_count, 1),
|
|
|
|
LogRateLimit = get_integer_env(log_rate_limit, 100),
|
2021-01-27 09:24:05 +01:00
|
|
|
ConsoleLevel0 = case quiet_mode() of
|
|
|
|
true -> critical;
|
|
|
|
_ -> Level
|
|
|
|
end,
|
2019-10-25 10:44:04 +02:00
|
|
|
ConsoleLevel = case get_lager_version() >= "3.6.0" of
|
2021-01-27 09:24:05 +01:00
|
|
|
true -> [{level, ConsoleLevel0}];
|
|
|
|
false -> ConsoleLevel0
|
2019-10-25 10:44:04 +02:00
|
|
|
end,
|
|
|
|
application:set_env(lager, error_logger_hwm, LogRateLimit),
|
|
|
|
application:set_env(
|
|
|
|
lager, handlers,
|
|
|
|
[{lager_console_backend, ConsoleLevel},
|
|
|
|
{lager_file_backend, [{file, ConsoleLog}, {level, Level}, {date, LogRotateDate},
|
|
|
|
{count, LogRotateCount}, {size, LogRotateSize}]},
|
|
|
|
{lager_file_backend, [{file, ErrorLog}, {level, error}, {date, LogRotateDate},
|
|
|
|
{count, LogRotateCount}, {size, LogRotateSize}]}]),
|
|
|
|
application:set_env(lager, crash_log, CrashLog),
|
|
|
|
application:set_env(lager, crash_log_date, LogRotateDate),
|
|
|
|
application:set_env(lager, crash_log_size, LogRotateSize),
|
|
|
|
application:set_env(lager, crash_log_count, LogRotateCount),
|
|
|
|
ejabberd:start_app(lager),
|
|
|
|
lists:foreach(fun(Handler) ->
|
|
|
|
lager:set_loghwm(Handler, LogRateLimit)
|
|
|
|
end, gen_event:which_handlers(lager_event)).
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec restart() -> ok.
|
2019-10-25 10:44:04 +02:00
|
|
|
restart() ->
|
|
|
|
Level = ejabberd_option:loglevel(),
|
|
|
|
application:stop(lager),
|
|
|
|
start(Level).
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec reopen_log() -> ok.
|
2019-10-25 10:44:04 +02:00
|
|
|
reopen_log() ->
|
|
|
|
ok.
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec rotate_log() -> ok.
|
2019-10-25 10:44:04 +02:00
|
|
|
rotate_log() ->
|
|
|
|
catch lager_crash_log ! rotate,
|
|
|
|
lists:foreach(
|
|
|
|
fun({lager_file_backend, File}) ->
|
|
|
|
whereis(lager_event) ! {rotate, File};
|
|
|
|
(_) ->
|
|
|
|
ok
|
|
|
|
end, gen_event:which_handlers(lager_event)).
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec get() -> loglevel().
|
2019-10-25 10:44:04 +02:00
|
|
|
get() ->
|
|
|
|
Handlers = get_lager_handlers(),
|
|
|
|
lists:foldl(fun(lager_console_backend, _Acc) ->
|
|
|
|
lager:get_loglevel(lager_console_backend);
|
|
|
|
(elixir_logger_backend, _Acc) ->
|
|
|
|
lager:get_loglevel(elixir_logger_backend);
|
|
|
|
(_, Acc) ->
|
|
|
|
Acc
|
|
|
|
end,
|
|
|
|
none, Handlers).
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec set(0..5 | loglevel()) -> ok.
|
2019-10-25 10:44:04 +02:00
|
|
|
set(N) when is_integer(N), N>=0, N=<5 ->
|
|
|
|
set(convert_loglevel(N));
|
|
|
|
set(Level) when ?is_loglevel(Level) ->
|
|
|
|
case get() of
|
|
|
|
Level ->
|
|
|
|
ok;
|
|
|
|
_ ->
|
|
|
|
ConsoleLog = get_log_path(),
|
2021-01-27 09:24:05 +01:00
|
|
|
QuietMode = quiet_mode(),
|
2019-10-25 10:44:04 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun({lager_file_backend, File} = H) when File == ConsoleLog ->
|
|
|
|
lager:set_loglevel(H, Level);
|
2021-01-27 09:24:05 +01:00
|
|
|
(lager_console_backend = H) when not QuietMode ->
|
2019-10-25 10:44:04 +02:00
|
|
|
lager:set_loglevel(H, Level);
|
|
|
|
(elixir_logger_backend = H) ->
|
|
|
|
lager:set_loglevel(H, Level);
|
|
|
|
(_) ->
|
|
|
|
ok
|
|
|
|
end, get_lager_handlers())
|
|
|
|
end,
|
|
|
|
case Level of
|
|
|
|
debug -> xmpp:set_config([{debug, true}]);
|
|
|
|
_ -> xmpp:set_config([{debug, false}])
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_lager_handlers() ->
|
|
|
|
case catch gen_event:which_handlers(lager_event) of
|
|
|
|
{'EXIT',noproc} ->
|
|
|
|
[];
|
|
|
|
Result ->
|
|
|
|
Result
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec get_lager_version() -> string().
|
|
|
|
get_lager_version() ->
|
|
|
|
Apps = application:loaded_applications(),
|
|
|
|
case lists:keyfind(lager, 1, Apps) of
|
|
|
|
{_, _, Vsn} -> Vsn;
|
|
|
|
false -> "0.0.0"
|
|
|
|
end.
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec flush() -> ok.
|
2019-10-25 10:44:04 +02:00
|
|
|
flush() ->
|
2019-10-25 14:52:05 +02:00
|
|
|
application:stop(lager),
|
|
|
|
application:stop(sasl).
|
2019-10-25 10:44:04 +02:00
|
|
|
|
|
|
|
-else.
|
|
|
|
-include_lib("kernel/include/logger.hrl").
|
|
|
|
|
|
|
|
-spec start() -> ok | {error, term()}.
|
|
|
|
start() ->
|
|
|
|
start(info).
|
|
|
|
|
2017-12-17 19:03:40 +01:00
|
|
|
start(Level) ->
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
EjabberdLog = get_log_path(),
|
|
|
|
Dir = filename:dirname(EjabberdLog),
|
2013-06-27 10:58:56 +02:00
|
|
|
ErrorLog = filename:join([Dir, "error.log"]),
|
2015-01-22 12:40:27 +01:00
|
|
|
LogRotateSize = get_integer_env(log_rotate_size, 10*1024*1024),
|
|
|
|
LogRotateCount = get_integer_env(log_rotate_count, 1),
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
Config = #{max_no_bytes => LogRotateSize,
|
|
|
|
max_no_files => LogRotateCount,
|
|
|
|
filesync_repeat_interval => no_repeat,
|
2020-06-23 21:27:12 +02:00
|
|
|
file_check => 1000,
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
sync_mode_qlen => 1000,
|
|
|
|
drop_mode_qlen => 1000,
|
|
|
|
flush_qlen => 5000},
|
|
|
|
FmtConfig = #{legacy_header => false,
|
|
|
|
time_designator => $ ,
|
|
|
|
max_size => 100*1024,
|
|
|
|
single_line => false},
|
|
|
|
FileFmtConfig = FmtConfig#{template => file_template()},
|
|
|
|
ConsoleFmtConfig = FmtConfig#{template => console_template()},
|
2019-10-23 15:03:48 +02:00
|
|
|
try
|
|
|
|
ok = logger:set_primary_config(level, Level),
|
|
|
|
ok = logger:update_formatter_config(default, ConsoleFmtConfig),
|
2021-01-27 09:24:05 +01:00
|
|
|
case quiet_mode() of
|
|
|
|
true ->
|
|
|
|
ok = logger:set_handler_config(default, level, critical);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
2019-10-23 15:03:48 +02:00
|
|
|
case logger:add_primary_filter(progress_report,
|
|
|
|
{fun ?MODULE:progress_filter/2, stop}) of
|
|
|
|
ok -> ok;
|
|
|
|
{error, {already_exist, _}} -> ok
|
|
|
|
end,
|
|
|
|
case logger:add_handler(ejabberd_log, logger_std_h,
|
|
|
|
#{level => all,
|
2019-10-25 10:44:04 +02:00
|
|
|
config => Config#{file => EjabberdLog},
|
2019-10-23 15:03:48 +02:00
|
|
|
formatter => {logger_formatter, FileFmtConfig}}) of
|
|
|
|
ok -> ok;
|
|
|
|
{error, {already_exist, _}} -> ok
|
|
|
|
end,
|
|
|
|
case logger:add_handler(error_log, logger_std_h,
|
|
|
|
#{level => error,
|
2019-10-25 10:44:04 +02:00
|
|
|
config => Config#{file => ErrorLog},
|
2019-10-23 15:03:48 +02:00
|
|
|
formatter => {logger_formatter, FileFmtConfig}}) of
|
|
|
|
ok -> ok;
|
|
|
|
{error, {already_exist, _}} -> ok
|
|
|
|
end
|
|
|
|
catch _:{Tag, Err} when Tag == badmatch; Tag == case_clause ->
|
|
|
|
?LOG_CRITICAL("Failed to set logging: ~p", [Err]),
|
|
|
|
Err
|
|
|
|
end.
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec restart() -> ok.
|
2017-12-17 19:03:40 +01:00
|
|
|
restart() ->
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
ok.
|
|
|
|
|
2019-10-18 21:00:37 +02:00
|
|
|
progress_filter(#{level:=info,msg:={report,#{label:={_,progress}}}} = Event, _) ->
|
|
|
|
case get() of
|
|
|
|
debug ->
|
|
|
|
logger_filters:progress(Event#{level => debug}, log);
|
|
|
|
_ ->
|
|
|
|
stop
|
|
|
|
end;
|
|
|
|
progress_filter(Event, _) ->
|
|
|
|
Event.
|
|
|
|
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
console_template() ->
|
2019-10-18 21:00:37 +02:00
|
|
|
[time, " [", level, "] " | msg()].
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
|
|
|
|
file_template() ->
|
|
|
|
[time, " [", level, "] ", pid,
|
2019-10-18 21:00:37 +02:00
|
|
|
{mfa, ["@", mfa, {line, [":", line], []}], []}, " " | msg()].
|
|
|
|
|
|
|
|
msg() ->
|
|
|
|
[{logger_formatter, [[logger_formatter, title], ":", io_lib:nl()], []},
|
|
|
|
msg, io_lib:nl()].
|
2017-12-17 19:03:40 +01:00
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec reopen_log() -> ok.
|
2013-06-27 10:58:56 +02:00
|
|
|
reopen_log() ->
|
2015-12-08 22:48:04 +01:00
|
|
|
ok.
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec rotate_log() -> ok.
|
2015-12-08 22:48:04 +01:00
|
|
|
rotate_log() ->
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
ok.
|
2013-06-27 10:58:56 +02:00
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec get() -> loglevel().
|
2013-06-27 10:58:56 +02:00
|
|
|
get() ->
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
#{level := Level} = logger:get_primary_config(),
|
|
|
|
Level.
|
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec set(0..5 | loglevel()) -> ok.
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
set(N) when is_integer(N), N>=0, N=<5 ->
|
|
|
|
set(convert_loglevel(N));
|
|
|
|
set(Level) when ?is_loglevel(Level) ->
|
|
|
|
case get() of
|
|
|
|
Level -> ok;
|
|
|
|
PrevLevel ->
|
|
|
|
?LOG_NOTICE("Changing loglevel from '~s' to '~s'",
|
|
|
|
[PrevLevel, Level]),
|
|
|
|
logger:set_primary_config(level, Level),
|
|
|
|
case Level of
|
|
|
|
debug -> xmpp:set_config([{debug, true}]);
|
|
|
|
_ -> xmpp:set_config([{debug, false}])
|
|
|
|
end
|
2016-03-09 19:12:56 +01:00
|
|
|
end.
|
2018-09-07 17:03:36 +02:00
|
|
|
|
2020-05-11 19:37:47 +02:00
|
|
|
-spec flush() -> ok.
|
Replace lager with built-in new logging API
This change requires Erlang/OTP-21.0 or higher.
The commit also deprecates the following options:
- log_rotate_date
- log_rate_limit
Furthermore, these options have no effect. The logger now fully
relies on log_rotate_size, that cannot be 0 anymore.
The loglevel option now accepts levels in literal formats.
Those are: none, emergency, alert, critical, error, warning, notice, info, debug.
Old integer values (0-5) are still supported and automatically converted
into literal format.
2019-10-18 18:12:32 +02:00
|
|
|
flush() ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(#{id := HandlerId, module := logger_std_h}) ->
|
|
|
|
logger_std_h:filesync(HandlerId);
|
|
|
|
(#{id := HandlerId, module := logger_disk_log_h}) ->
|
|
|
|
logger_disk_log_h:filesync(HandlerId);
|
|
|
|
(_) ->
|
|
|
|
ok
|
|
|
|
end, logger:get_handler_config()).
|
2019-10-25 10:44:04 +02:00
|
|
|
|
|
|
|
-endif.
|