Merge pull request #9877 from zhongwencool/boot-app-logger-refresh
fix: primary logger level not update
This commit is contained in:
commit
70d23dabe9
|
@ -67,12 +67,16 @@ post_config_update(_ConfPath, _Req, _NewConf, _OldConf, _AppEnvs) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
maybe_update_log_level(NewLevel) ->
|
maybe_update_log_level(NewLevel) ->
|
||||||
OldLevel = application:get_env(kernel, logger_level, warning),
|
OldLevel = emqx_logger:get_primary_log_level(),
|
||||||
case OldLevel =:= NewLevel of
|
case OldLevel =:= NewLevel of
|
||||||
true ->
|
true ->
|
||||||
%% no change
|
%% no change
|
||||||
ok;
|
ok;
|
||||||
false ->
|
false ->
|
||||||
|
ok = emqx_logger:set_primary_log_level(NewLevel),
|
||||||
|
%% also update kernel's logger_level for troubleshooting
|
||||||
|
%% what is actually in effect is the logger's primary log level
|
||||||
|
ok = application:set_env(kernel, logger_level, NewLevel),
|
||||||
log_to_console("Config override: log level is set to '~p'~n", [NewLevel])
|
log_to_console("Config override: log level is set to '~p'~n", [NewLevel])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -97,7 +101,7 @@ update_log_handlers(NewHandlers) ->
|
||||||
end,
|
end,
|
||||||
AddsAndUpdates = lists:filtermap(MapFn, NewHandlers),
|
AddsAndUpdates = lists:filtermap(MapFn, NewHandlers),
|
||||||
lists:foreach(fun update_log_handler/1, Removes ++ AddsAndUpdates),
|
lists:foreach(fun update_log_handler/1, Removes ++ AddsAndUpdates),
|
||||||
_ = application:set_env(kernel, logger, NewHandlers),
|
ok = application:set_env(kernel, logger, NewHandlers),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
update_log_handler({removed, Id}) ->
|
update_log_handler({removed, Id}) ->
|
||||||
|
@ -107,7 +111,17 @@ update_log_handler({Action, {handler, Id, Mod, Conf}}) ->
|
||||||
log_to_console("Config override: ~s is ~p~n", [id_for_log(Id), Action]),
|
log_to_console("Config override: ~s is ~p~n", [id_for_log(Id), Action]),
|
||||||
% may return {error, {not_found, Id}}
|
% may return {error, {not_found, Id}}
|
||||||
_ = logger:remove_handler(Id),
|
_ = logger:remove_handler(Id),
|
||||||
ok = logger:add_handler(Id, Mod, Conf).
|
case logger:add_handler(Id, Mod, Conf) of
|
||||||
|
ok ->
|
||||||
|
ok;
|
||||||
|
%% Don't crash here, otherwise the cluster rpc will retry the wrong handler forever.
|
||||||
|
{error, Reason} ->
|
||||||
|
log_to_console(
|
||||||
|
"Config override: ~s is ~p, but failed to add handler: ~p~n",
|
||||||
|
[id_for_log(Id), Action, Reason]
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
ok.
|
||||||
|
|
||||||
id_for_log(console) -> "log.console_handler";
|
id_for_log(console) -> "log.console_handler";
|
||||||
id_for_log(Other) -> "log.file_handlers." ++ atom_to_list(Other).
|
id_for_log(Other) -> "log.file_handlers." ++ atom_to_list(Other).
|
||||||
|
@ -115,7 +129,7 @@ id_for_log(Other) -> "log.file_handlers." ++ atom_to_list(Other).
|
||||||
atom(Id) when is_binary(Id) -> binary_to_atom(Id, utf8);
|
atom(Id) when is_binary(Id) -> binary_to_atom(Id, utf8);
|
||||||
atom(Id) when is_atom(Id) -> Id.
|
atom(Id) when is_atom(Id) -> Id.
|
||||||
|
|
||||||
%% @doc Translate raw config to app-env conpatible log handler configs list.
|
%% @doc Translate raw config to app-env compatible log handler configs list.
|
||||||
tr_handlers(Conf) ->
|
tr_handlers(Conf) ->
|
||||||
%% mute the default handler
|
%% mute the default handler
|
||||||
tr_console_handler(Conf) ++
|
tr_console_handler(Conf) ++
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
start(_Type, _Args) ->
|
start(_Type, _Args) ->
|
||||||
ok = maybe_load_config(),
|
ok = maybe_load_config(),
|
||||||
ok = emqx_persistent_session:init_db_backend(),
|
ok = emqx_persistent_session:init_db_backend(),
|
||||||
ok = emqx_config_logger:refresh_config(),
|
|
||||||
ok = maybe_start_quicer(),
|
ok = maybe_start_quicer(),
|
||||||
ok = emqx_bpapi:start(),
|
ok = emqx_bpapi:start(),
|
||||||
wait_boot_shards(),
|
wait_boot_shards(),
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
start(_StartType, _StartArgs) ->
|
start(_StartType, _StartArgs) ->
|
||||||
init_conf(),
|
init_conf(),
|
||||||
|
ok = emqx_config_logger:refresh_config(),
|
||||||
emqx_conf_sup:start_link().
|
emqx_conf_sup:start_link().
|
||||||
|
|
||||||
stop(_State) ->
|
stop(_State) ->
|
||||||
|
|
|
@ -13,7 +13,7 @@ Environment=HOME=/var/lib/emqx
|
||||||
# Enable logging to file
|
# Enable logging to file
|
||||||
Environment=EMQX_LOG__TO=default
|
Environment=EMQX_LOG__TO=default
|
||||||
|
|
||||||
# Start 'foregroun' but not 'start' (daemon) mode.
|
# Start 'foreground' but not 'start' (daemon) mode.
|
||||||
# Because systemd monitor/restarts 'simple' services
|
# Because systemd monitor/restarts 'simple' services
|
||||||
ExecStart=/bin/bash /usr/bin/emqx foreground
|
ExecStart=/bin/bash /usr/bin/emqx foreground
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue