Packages

otpbp

5.26.1
7.18.0 7.16.1 7.15.0 7.14.0 7.13.0 7.12.0 7.11.0 7.10.2 7.9.3 7.9.2 7.9.1 7.8.7 7.8.6 7.8.5 7.8.4 7.7.1 7.7.0 7.6.3 7.6.2 7.6.1 7.6.0 7.5.1 7.5.0 7.4.0 7.3.4 7.3.3 7.3.2 7.3.1 7.3.0 7.2.0 7.1.1 7.1.0 7.0.4 7.0.3 7.0.2 7.0.1 6.26.0 6.25.0 6.24.0 6.23.0 6.22.2 6.21.3 6.21.2 6.21.1 6.20.2 6.19.1 6.19.0 6.18.3 6.18.2 6.18.1 6.18.0 6.17.1 6.17.0 6.16.0 6.15.4 6.15.3 6.15.2 6.15.1 6.15.0 6.14.0 6.13.5 6.13.4 6.13.3 6.13.2 6.13.1 6.13.0 6.12.0 6.11.2 6.11.1 6.10.0 6.9.2 6.9.1 6.9.0 6.8.0 6.7.1 6.7.0 6.6.4 6.6.3 6.6.2 6.6.1 6.6.0 6.5.0 6.4.0 6.3.3 6.3.2 6.3.1 6.3.0 6.2.1 6.2.0 6.1.0 6.0.0 5.39.0 5.38.0 5.37.0 5.36.0 5.35.2 5.34.3 5.34.2 5.34.1 5.33.1 5.32.1 5.32.0 5.31.3 5.31.2 5.31.1 5.31.0 5.30.1 5.30.0 5.29.0 5.28.4 5.28.3 5.28.2 5.28.1 5.28.0 5.27.0 5.26.5 5.26.4 5.26.3 5.26.2 5.26.1 5.26.0 5.25.0 5.24.2 5.24.1 5.23.0 5.22.2 5.22.1 5.22.0 5.21.0 5.20.1 5.20.0 5.19.4 5.19.3 5.19.2 5.19.1 5.19.0 5.18.0 5.17.0 5.16.3 5.16.1 5.16.0 5.15.1 5.15.0 5.14.0 5.13.1 5.13.0 5.12.1 5.12.0 5.11.2 5.11.1 5.10.1 5.10.0 5.9.0 5.8.0 5.7.0 5.6.1 5.6.0 5.5.0 5.4.2 5.4.1 5.4.0 5.3.0 5.2.2 5.2.1 5.2.0 5.1.2 5.1.1 4.79.0 4.78.0 4.77.0 4.76.2 4.75.3 4.75.2 4.75.1 4.74.0 4.73.1 4.73.0 4.72.3 4.72.2 4.72.1 4.72.0 4.71.1 4.71.0 4.70.0 4.69.4 4.69.3 4.69.2 4.69.1 4.69.0 4.68.0 4.67.5 4.67.4 4.67.3 4.67.2 4.67.0 4.66.0 4.65.2 4.65.1 4.64.0 4.63.2 4.63.1 4.63.0 4.62.0 4.61.1 4.61.0 4.60.4 4.60.3 4.60.2 4.60.1 4.60.0 4.59.0 4.58.0 4.57.2 4.57.1 4.57.0 4.56.2 4.56.1 4.56.0 4.55.0 4.54.0 4.53.0 4.52.1 4.52.0 4.51.3 4.51.2 4.51.0 4.50.0 4.49.3 4.49.2

OTP backports

Current section

Files

Jump to
otpbp src otpbp_logger.erl
Raw

src/otpbp_logger.erl

-module(otpbp_logger).
-ifndef(HAVE_logger__set_application_level_2).
% OTP 21.1
-ifdef(HAVE_logger__set_module_level_2).
-export([set_application_level/2]).
-endif.
-endif.
-ifndef(HAVE_logger__unset_application_level_1).
% OTP 21.1
-ifdef(HAVE_logger__unset_module_level_1).
-export([unset_application_level/1]).
-endif.
-endif.
-ifndef(HAVE_logger__i_0).
% OTP 21.3
-ifdef(HAVE_logger__get_config_0).
-export([i/0]).
-endif.
-endif.
-ifndef(HAVE_logger__i_1).
% OTP 21.3
-ifdef(HAVE_logger__get_handler_config_0).
-export([i/1]).
-endif.
-endif.
-ifndef(HAVE_logger__timestamp_0).
% OTP 21.3
-export([timestamp/0]).
-endif.
-ifndef(HAVE_logger__reconfigure_0).
% OTP 24.2
-ifdef(HAVE_logger__get_handler_config_0).
-export([reconfigure/0]).
-endif.
-endif.
-ifndef(HAVE_logger__set_application_level_2).
-ifdef(HAVE_logger__set_module_level_2).
set_application_level(App, Level) ->
case application:get_key(App, modules) of
{ok, Modules} -> logger:set_module_level(Modules, Level);
undefined -> {error, {not_loaded, App}}
end.
-endif.
-endif.
-ifndef(HAVE_logger__unset_application_level_1).
-ifdef(HAVE_logger__unset_module_level_1).
unset_application_level(App) ->
case application:get_key(App, modules) of
{ok, Modules} -> logger:unset_module_level(Modules);
undefined -> {error, {not_loaded, App}}
end.
-endif.
-endif.
-ifndef(HAVE_logger__i_0).
-ifdef(HAVE_logger__get_config_0).
i() ->
#{primary := Primary, handlers := HandlerConfigs, module_levels := Modules} = logger:get_config(),
M = modifier(),
i_primary(Primary, M),
i_handlers(HandlerConfigs, M),
i_modules(Modules, M).
-ifndef(NEED_modifier_0).
-define(NEED_modifier_0, true).
-endif.
-endif.
-endif.
-ifndef(HAVE_logger__i_1).
-ifdef(HAVE_logger__get_handler_config_0).
i(primary) -> i_primary(logger:get_primary_config(), modifier());
i(handlers) -> i_handlers(logger:get_handler_config(), modifier());
i(proxy) -> ok;
i(modules) -> i_modules(logger:get_module_level(), modifier());
i(HandlerId) when is_atom(HandlerId) ->
case logger:get_handler_config(HandlerId) of
{ok, HandlerConfig} -> i_handlers([HandlerConfig], modifier());
Error -> Error
end;
i(What) -> error(badarg, [What]).
-ifndef(NEED_modifier_0).
-define(NEED_modifier_0, true).
-endif.
-endif.
-endif.
-ifdef(NEED_modifier_0).
i_primary(#{level := Level, filters := Filters, filter_default := FilterDefault}, M) ->
io:fwrite("Primary configuration: ~n",
" Level: ~p~n"
" Filter Default: ~p~n"
" Filters: ~n",
[Level, FilterDefault]),
print_filters(" ", Filters, M).
i_handlers(HandlerConfigs, M) ->
io:put_chars("Handler configuration: \n"),
print_handlers(HandlerConfigs, M).
i_modules(Modules, M) ->
io:put_chars("Level set per module: \n"),
print_module_levels(Modules,M).
encoding() ->
case lists:keyfind(encoding, 1, io:getopts()) of
{_encoding, Enc} -> Enc;
_false -> latin1
end.
modifier() -> modifier(encoding()).
modifier(latin1) -> "";
modifier(_) -> "t".
print_filters(Indent, {Id, {Fun, Arg}}, M) ->
io:fwrite("~sId: ~" ++ M ++ "p~n"
"~s Fun: ~" ++ M ++ "p~n"
"~s Arg: ~" ++ M ++ "p~n",
[Indent, Id, Indent, Fun, Indent, Arg]);
print_filters(Indent, [], _M) -> io:fwrite("~s(none)~n", [Indent]);
print_filters(Indent, Filters, M) -> lists:foreach(fun(Filter) -> print_filters(Indent, Filter, M) end, Filters).
print_handlers(#{id := Id, module := Module, level := Level, filters := Filters, filter_default := FilterDefault,
formatter := {FormatterModule, FormatterConfig}} = Config,
M) ->
io:fwrite(" Id: ~" ++ M ++ "p~n"
" Module: ~p~n"
" Level: ~p~n"
" Formatter:~n"
" Module: ~p~n"
" Config:~n",
[Id, Module, Level, FormatterModule]),
print_custom(" ", FormatterConfig, M),
io:fwrite(" Filter Default: ~p~n"
" Filters:~n",
[FilterDefault]),
print_filters(" ", Filters, M),
case Config of
#{config := HandlerConfig} ->
io:put_chars(" Handler Config:\n"),
print_custom(" ", HandlerConfig, M);
_ -> ok
end,
case maps:without([filter_default, filters, formatter, level, module, id, config], Config) of
Empty when map_size(Empty) =:= 0 -> ok;
Unhandled ->
io:put_chars(" Custom Config:\n"),
print_custom(" ", Unhandled, M)
end;
print_handlers([], _M) -> io:put_chars(" (none)\n");
print_handlers(HandlerConfigs, M) ->
lists:foreach(fun(HandlerConfig) -> print_handlers(HandlerConfig, M) end, HandlerConfigs).
print_custom(Indent, {Key, Value}, M) -> io:fwrite("~s~" ++ M ++ "p: ~" ++ M ++ "p~n", [Indent, Key, Value]);
print_custom(Indent, Map, M) when is_map(Map) -> print_custom(Indent, lists:keysort(1, maps:to_list(Map)), M);
print_custom(Indent, List, M) when is_list(List), is_tuple(hd(List)) ->
lists:foreach(fun(X) -> print_custom(Indent, X, M) end, List);
print_custom(Indent, Value, M) -> io:fwrite("~s~" ++ M ++ "p~n", [Indent, Value]).
print_module_levels({Module,Level},M) ->
io:fwrite(" Module: ~" ++ M ++ "p~n"
" Level: ~p~n",
[Module, Level]);
print_module_levels([],_M) -> io:put_chars(" (none)\n");
print_module_levels(Modules,M) -> lists:foreach(fun(Module) -> print_module_levels(Module, M) end, Modules).
-endif.
-ifndef(HAVE_logger__timestamp_0).
timestamp() -> os:system_time(microsecond).
-endif.
-ifndef(HAVE_logger__reconfigure_0).
-ifdef(HAVE_logger__get_handler_config_0).
-define(DEFAULT_HANDLER_FILTERS, ?DEFAULT_HANDLER_FILTERS([otp])).
-define(DEFAULT_HANDLER_FILTERS(Domain),
[{remote_gl, {fun logger_filters:remote_gl/2, stop}},
{domain, {fun logger_filters:domain/2, {log, super, Domain}}},
{no_domain, {fun logger_filters:domain/2, {log, undefined, []}}}]).
reconfigure() ->
F = fun(#{id := Id}) ->
case logger:remove_handler(Id) of
ok -> ok;
{error, Reason} -> throw({remove, Id, Reason})
end;
(_) -> ok
end,
try lists:foreach(F, logger:get_handler_config()),
ok = logger:add_handler(simple, logger_simple_h, #{filter_default => stop, filters => ?DEFAULT_HANDLER_FILTERS}),
logger:unset_module_level(),
logger:internal_init_logger() of
ok -> logger:add_handlers(kernel);
Error -> Error
catch
throw:Reason -> {error, Reason}
end.
-endif.
-endif.