25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

lager is the default logger, we need to reverse the define flag

This commit is contained in:
Mickael Remond 2016-01-23 18:43:06 +01:00
parent 7cc951ab1b
commit a3931e6b73
2 changed files with 62 additions and 60 deletions

View File

@ -74,7 +74,67 @@ opt_type(log_rate_limit) ->
opt_type(_) ->
[log_rotate_date, log_rotate_size, log_rotate_count, log_rate_limit].
-ifdef(LAGER).
%% Default logger module is LAGER, defined in else clause.
%% TODO: Remove p1_logger usage and allow using Elixir logger if running in Elixir context.
-ifdef(P1LOGGER).
start() ->
set(4),
LogPath = get_log_path(),
error_logger:add_report_handler(p1_logger_h, LogPath),
ok.
reopen_log() ->
%% TODO: Use the Reopen log API for logger_h ?
p1_logger_h:reopen_log(),
reopen_sasl_log().
rotate_log() ->
%% Not implemented.
ok.
get() ->
p1_loglevel:get().
set(LogLevel) when LogLevel >=0, LogLevel =< 5 ->
p1_loglevel:set(LogLevel);
set(LogLevel) ->
throw({wrong_loglevel, LogLevel}).
%%%===================================================================
%%% Internal functions
%%%===================================================================
reopen_sasl_log() ->
case application:get_env(sasl,sasl_error_logger) of
{ok, {file, SASLfile}} ->
error_logger:delete_report_handler(sasl_report_file_h),
rotate_sasl_log(SASLfile),
error_logger:add_report_handler(sasl_report_file_h,
{SASLfile, get_sasl_error_logger_type()});
_ -> false
end,
ok.
rotate_sasl_log(Filename) ->
case file:read_file_info(Filename) of
{ok, _FileInfo} ->
file:rename(Filename, [Filename, ".0"]),
ok;
{error, _Reason} ->
ok
end.
%% Function copied from Erlang/OTP lib/sasl/src/sasl.erl which doesn't export it
get_sasl_error_logger_type () ->
case application:get_env (sasl, errlog_type) of
{ok, error} -> error;
{ok, progress} -> progress;
{ok, all} -> all;
{ok, Bad} -> exit ({bad_config, {sasl, {errlog_type, Bad}}});
_ -> all
end.
-else.
get_integer_env(Name, Default) ->
case application:get_env(ejabberd, Name) of
@ -183,62 +243,4 @@ set({_LogLevel, _}) ->
error_logger:error_msg("custom loglevels are not supported for 'lager'"),
{module, lager}.
-else.
start() ->
set(4),
LogPath = get_log_path(),
error_logger:add_report_handler(p1_logger_h, LogPath),
ok.
reopen_log() ->
%% TODO: Use the Reopen log API for logger_h ?
p1_logger_h:reopen_log(),
reopen_sasl_log().
rotate_log() ->
%% Not implemented.
ok.
get() ->
p1_loglevel:get().
set(LogLevel) when LogLevel >=0, LogLevel =< 5 ->
p1_loglevel:set(LogLevel);
set(LogLevel) ->
throw({wrong_loglevel, LogLevel}).
%%%===================================================================
%%% Internal functions
%%%===================================================================
reopen_sasl_log() ->
case application:get_env(sasl,sasl_error_logger) of
{ok, {file, SASLfile}} ->
error_logger:delete_report_handler(sasl_report_file_h),
rotate_sasl_log(SASLfile),
error_logger:add_report_handler(sasl_report_file_h,
{SASLfile, get_sasl_error_logger_type()});
_ -> false
end,
ok.
rotate_sasl_log(Filename) ->
case file:read_file_info(Filename) of
{ok, _FileInfo} ->
file:rename(Filename, [Filename, ".0"]),
ok;
{error, _Reason} ->
ok
end.
%% Function copied from Erlang/OTP lib/sasl/src/sasl.erl which doesn't export it
get_sasl_error_logger_type () ->
case application:get_env (sasl, errlog_type) of
{ok, error} -> error;
{ok, progress} -> progress;
{ok, all} -> all;
{ok, Bad} -> exit ({bad_config, {sasl, {errlog_type, Bad}}});
_ -> all
end.
-endif.

View File

@ -510,7 +510,7 @@ compile(_Module, _Spec, DestDir) ->
EjabBin = filename:dirname(code:which(ejabberd)),
EjabInc = filename:join(filename:dirname(EjabBin), "include"),
XmlHrl = filename:join(EjabInc, "xml.hrl"),
Logger = [{d, 'LAGER'} || code:is_loaded(lager)=/=false],
Logger = [{d, 'P1LOGGER'} || code:is_loaded(lager)==false],
ExtLib = [{d, 'NO_EXT_LIB'} || filelib:is_file(XmlHrl)],
Options = [{outdir, Ebin}, {i, "include"}, {i, EjabInc},
verbose, report_errors, report_warnings]