1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 01:39:35 +02:00

ejabberd_logger: Print log lines colorized in console when using rebar3

This commit is contained in:
Badlop 2025-08-04 10:30:57 +02:00
parent 7065cb69f1
commit d70ac7f7c5
2 changed files with 40 additions and 10 deletions

View file

@ -39,20 +39,46 @@
-else.
-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),
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),
begin ?LOG_INFO(Format, Args), ok end).
begin ?LOG_INFO(Format, Args,
#{clevel => ?CLEAD ++ ?CINFO,
ctext => ?CCLEAN}),
ok end).
-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),
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),
begin ?LOG_CRITICAL(Format, Args), ok end).
begin ?LOG_CRITICAL(Format, Args,
#{clevel => ?CLEAD++ ?CCRITICAL,
ctext => ?CMID ++ ?CCRITICAL}),
ok end).
-endif.
%% Use only when trying to troubleshoot test problem with ExUnit

View file

@ -47,6 +47,8 @@
-export_type([loglevel/0]).
-include("logger.hrl").
%%%===================================================================
%%% API
%%%===================================================================
@ -383,19 +385,21 @@ console_template() ->
false ->
[time, " [", level, "] " | msg()]
end.
msg() ->
[{logger_formatter, [[logger_formatter, title], ":", io_lib:nl()], []},
msg, io_lib:nl()].
-else.
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.
file_template() ->
[time, " [", level, "] ", pid,
{mfa, ["@", mfa, {line, [":", line], []}], []}, " " | msg()].
msg() ->
[{logger_formatter, [[logger_formatter, title], ":", io_lib:nl()], []},
msg, io_lib:nl()].
-spec reopen_log() -> ok.
reopen_log() ->
ok.