fix: primary logger level not update

This commit is contained in:
Zhongwen Deng 2023-02-01 11:16:30 +08:00
parent 7e8253e3af
commit 9cbad5297c
4 changed files with 9 additions and 5 deletions

View File

@ -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}) ->
@ -115,7 +119,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) ++

View File

@ -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(),

View File

@ -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) ->

View File

@ -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