Merge pull request #11062 from zhongwencool/log-file-rename

This commit is contained in:
zhongwencool 2023-06-15 20:51:52 +08:00 committed by GitHub
commit 9b56f116f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 12 deletions

View File

@ -151,7 +151,7 @@ tr_file_handler({HandlerName, SubConf}) ->
level => conf_get("level", SubConf), level => conf_get("level", SubConf),
config => (log_handler_conf(SubConf))#{ config => (log_handler_conf(SubConf))#{
type => wrap, type => wrap,
file => conf_get("to", SubConf), file => conf_get("path", SubConf),
max_no_files => conf_get("rotation_count", SubConf), max_no_files => conf_get("rotation_count", SubConf),
max_no_bytes => conf_get("rotation_size", SubConf) max_no_bytes => conf_get("rotation_size", SubConf)
}, },

View File

@ -909,13 +909,13 @@ fields("console_handler") ->
log_handler_common_confs(console); log_handler_common_confs(console);
fields("log_file_handler") -> fields("log_file_handler") ->
[ [
{"to", {"path",
sc( sc(
file(), file(),
#{ #{
desc => ?DESC("log_file_handler_file"), desc => ?DESC("log_file_handler_file"),
default => <<"${EMQX_LOG_DIR}/emqx.log">>, default => <<"${EMQX_LOG_DIR}/emqx.log">>,
aliases => [file], aliases => [file, to],
importance => ?IMPORTANCE_HIGH, importance => ?IMPORTANCE_HIGH,
converter => fun(Path, Opts) -> converter => fun(Path, Opts) ->
emqx_schema:naive_env_interpolation(ensure_unicode_path(Path, Opts)) emqx_schema:naive_env_interpolation(ensure_unicode_path(Path, Opts))

View File

@ -43,7 +43,7 @@
file { file {
enable = true enable = true
level = info level = info
to = \"log/emqx.log\" path = \"log/emqx.log\"
} }
} }
"""). """).
@ -67,7 +67,7 @@ t_log_conf(_Conf) ->
<<"rotation_count">> => 10, <<"rotation_count">> => 10,
<<"rotation_size">> => <<"50MB">>, <<"rotation_size">> => <<"50MB">>,
<<"time_offset">> => <<"system">>, <<"time_offset">> => <<"system">>,
<<"to">> => <<"log/emqx.log">> <<"path">> => <<"log/emqx.log">>
}, },
ExpectLog1 = #{ ExpectLog1 = #{
<<"console">> => <<"console">> =>

View File

@ -206,7 +206,7 @@ log_rotation_count_limit_test() ->
""" """
log.file { log.file {
enable = true enable = true
to = \"log/emqx.log\" path = \"log/emqx.log\"
formatter = text formatter = text
level = debug level = debug
rotation = {count = ~w} rotation = {count = ~w}
@ -434,7 +434,7 @@ log_path_test_() ->
#{<<"log">> => #{<<"file_handlers">> => #{<<"name1">> => #{<<"file">> => Path}}}} #{<<"log">> => #{<<"file_handlers">> => #{<<"name1">> => #{<<"file">> => Path}}}}
end, end,
Assert = fun(Name, Path, Conf) -> Assert = fun(Name, Path, Conf) ->
?assertMatch(#{log := #{file := #{Name := #{to := Path}}}}, Conf) ?assertMatch(#{log := #{file := #{Name := #{path := Path}}}}, Conf)
end, end,
[ [
@ -452,7 +452,7 @@ log_path_test_() ->
"handler_name" := "handler_name" :=
#{ #{
kind := validation_error, kind := validation_error,
path := "log.file.name1.to", path := "log.file.name1.path",
reason := {"bad_file_path_string", _} reason := {"bad_file_path_string", _}
} }
} }
@ -471,7 +471,7 @@ log_path_test_() ->
"handler_name" := "handler_name" :=
#{ #{
kind := validation_error, kind := validation_error,
path := "log.file.name1.to", path := "log.file.name1.path",
reason := {"not_string", _} reason := {"not_string", _}
} }
} }

View File

@ -100,7 +100,7 @@ t_log(_Config) ->
File = "log/emqx-test.log", File = "log/emqx-test.log",
%% update handler %% update handler
Log1 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"enable">>], Log, true), Log1 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"enable">>], Log, true),
Log2 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"to">>], Log1, File), Log2 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"path">>], Log1, File),
{ok, #{}} = update_config(<<"log">>, Log2), {ok, #{}} = update_config(<<"log">>, Log2),
{ok, Log3} = logger:get_handler_config(default), {ok, Log3} = logger:get_handler_config(default),
?assertMatch(#{config := #{file := File}}, Log3), ?assertMatch(#{config := #{file := File}}, Log3),
@ -116,7 +116,7 @@ t_log(_Config) ->
Handler = emqx_utils_maps:deep_get([<<"file">>, <<"default">>], Log2), Handler = emqx_utils_maps:deep_get([<<"file">>, <<"default">>], Log2),
NewLog1 = emqx_utils_maps:deep_put([<<"file">>, <<"new">>], Log2, Handler), NewLog1 = emqx_utils_maps:deep_put([<<"file">>, <<"new">>], Log2, Handler),
NewLog2 = emqx_utils_maps:deep_put( NewLog2 = emqx_utils_maps:deep_put(
[<<"file">>, <<"new">>, <<"to">>], NewLog1, File1 [<<"file">>, <<"new">>, <<"path">>], NewLog1, File1
), ),
{ok, #{}} = update_config(<<"log">>, NewLog2), {ok, #{}} = update_config(<<"log">>, NewLog2),
{ok, Log4} = logger:get_handler_config(new), {ok, Log4} = logger:get_handler_config(new),

View File

@ -35,7 +35,7 @@ init_per_testcase(t_log_path, Config) ->
Log = emqx_conf:get_raw([log], #{}), Log = emqx_conf:get_raw([log], #{}),
File = "log/emqx-test.log", File = "log/emqx-test.log",
Log1 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"enable">>], Log, true), Log1 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"enable">>], Log, true),
Log2 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"to">>], Log1, File), Log2 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"path">>], Log1, File),
{ok, #{}} = emqx_conf:update([log], Log2, #{rawconf_with_defaults => true}), {ok, #{}} = emqx_conf:update([log], Log2, #{rawconf_with_defaults => true}),
Config; Config;
init_per_testcase(_, Config) -> init_per_testcase(_, Config) ->

View File

@ -0,0 +1 @@
Rename `log.file.to` to `log.file.path`.