mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
ejabberd_logger: Print log lines colorized in console when using rebar3
This commit is contained in:
parent
7065cb69f1
commit
d70ac7f7c5
2 changed files with 40 additions and 10 deletions
|
@ -39,20 +39,46 @@
|
||||||
-else.
|
-else.
|
||||||
-include_lib("kernel/include/logger.hrl").
|
-include_lib("kernel/include/logger.hrl").
|
||||||
|
|
||||||
|
-define(CLEAD, "\e[1"). % bold
|
||||||
|
-define(CMID, "\e[0"). % normal
|
||||||
|
-define(CCLEAN, "\e[0m"). % clean
|
||||||
|
|
||||||
|
-define(CDEFAULT, ";49;95m"). % light magenta
|
||||||
|
-define(CDEBUG, ";49;90m"). % dark gray
|
||||||
|
-define(CINFO, ";49;92m"). % green
|
||||||
|
-define(CWARNING, ";49;93m"). % light yellow
|
||||||
|
-define(CERROR, ";49;91m"). % light magenta
|
||||||
|
-define(CCRITICAL,";49;31m"). % light red
|
||||||
|
|
||||||
-define(DEBUG(Format, Args),
|
-define(DEBUG(Format, Args),
|
||||||
begin ?LOG_DEBUG(Format, Args), ok end).
|
begin ?LOG_DEBUG(Format, Args,
|
||||||
|
#{clevel => ?CLEAD ++ ?CDEBUG,
|
||||||
|
ctext => ?CMID ++ ?CDEBUG}),
|
||||||
|
ok end).
|
||||||
|
|
||||||
-define(INFO_MSG(Format, Args),
|
-define(INFO_MSG(Format, Args),
|
||||||
begin ?LOG_INFO(Format, Args), ok end).
|
begin ?LOG_INFO(Format, Args,
|
||||||
|
#{clevel => ?CLEAD ++ ?CINFO,
|
||||||
|
ctext => ?CCLEAN}),
|
||||||
|
ok end).
|
||||||
|
|
||||||
-define(WARNING_MSG(Format, Args),
|
-define(WARNING_MSG(Format, Args),
|
||||||
begin ?LOG_WARNING(Format, Args), ok end).
|
begin ?LOG_WARNING(Format, Args,
|
||||||
|
#{clevel => ?CLEAD ++ ?CWARNING,
|
||||||
|
ctext => ?CMID ++ ?CWARNING}),
|
||||||
|
ok end).
|
||||||
|
|
||||||
-define(ERROR_MSG(Format, Args),
|
-define(ERROR_MSG(Format, Args),
|
||||||
begin ?LOG_ERROR(Format, Args), ok end).
|
begin ?LOG_ERROR(Format, Args,
|
||||||
|
#{clevel => ?CLEAD ++ ?CERROR,
|
||||||
|
ctext => ?CMID ++ ?CERROR}),
|
||||||
|
ok end).
|
||||||
|
|
||||||
-define(CRITICAL_MSG(Format, Args),
|
-define(CRITICAL_MSG(Format, Args),
|
||||||
begin ?LOG_CRITICAL(Format, Args), ok end).
|
begin ?LOG_CRITICAL(Format, Args,
|
||||||
|
#{clevel => ?CLEAD++ ?CCRITICAL,
|
||||||
|
ctext => ?CMID ++ ?CCRITICAL}),
|
||||||
|
ok end).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
%% Use only when trying to troubleshoot test problem with ExUnit
|
%% Use only when trying to troubleshoot test problem with ExUnit
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
|
|
||||||
-export_type([loglevel/0]).
|
-export_type([loglevel/0]).
|
||||||
|
|
||||||
|
-include("logger.hrl").
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
@ -383,19 +385,21 @@ console_template() ->
|
||||||
false ->
|
false ->
|
||||||
[time, " [", level, "] " | msg()]
|
[time, " [", level, "] " | msg()]
|
||||||
end.
|
end.
|
||||||
|
msg() ->
|
||||||
|
[{logger_formatter, [[logger_formatter, title], ":", io_lib:nl()], []},
|
||||||
|
msg, io_lib:nl()].
|
||||||
-else.
|
-else.
|
||||||
console_template() ->
|
console_template() ->
|
||||||
[time, " [", level, "] " | msg()].
|
[time, " ", ?CLEAD, ?CDEFAULT, clevel, "[", level, "] ", ?CMID, ?CDEFAULT, ctext | msg()].
|
||||||
|
msg() ->
|
||||||
|
[{logger_formatter, [[logger_formatter, title], ":", io_lib:nl()], []},
|
||||||
|
msg, ?CCLEAN, io_lib:nl()].
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
file_template() ->
|
file_template() ->
|
||||||
[time, " [", level, "] ", pid,
|
[time, " [", level, "] ", pid,
|
||||||
{mfa, ["@", mfa, {line, [":", line], []}], []}, " " | msg()].
|
{mfa, ["@", mfa, {line, [":", line], []}], []}, " " | msg()].
|
||||||
|
|
||||||
msg() ->
|
|
||||||
[{logger_formatter, [[logger_formatter, title], ":", io_lib:nl()], []},
|
|
||||||
msg, io_lib:nl()].
|
|
||||||
|
|
||||||
-spec reopen_log() -> ok.
|
-spec reopen_log() -> ok.
|
||||||
reopen_log() ->
|
reopen_log() ->
|
||||||
ok.
|
ok.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue