From eb015f1a675732529005ae6e077dcbe88cfbcdd7 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 11 Feb 2026 15:44:53 +0800 Subject: [PATCH] lager to logger --- config/sys-dev.config | 50 ++++++++++++++++++------------------------ config/sys-prod.config | 50 ++++++++++++++++++------------------------ rebar.lock | 7 ++++++ 3 files changed, 49 insertions(+), 58 deletions(-) diff --git a/config/sys-dev.config b/config/sys-dev.config index d6cee1f..b4635b4 100644 --- a/config/sys-dev.config +++ b/config/sys-dev.config @@ -61,37 +61,29 @@ ]}, %% 系统日志配置,系统日志为lager, 支持日志按日期自动分割 - {lager, [ - {colored, true}, - %% Whether to write a crash log, and where. Undefined means no crash logger. - {crash_log, "trade_hub.crash.log"}, - %% Maximum size in bytes of events in the crash log - defaults to 65536 - {crash_log_msg_size, 65536}, - %% Maximum size of the crash log in bytes, before its rotated, set - %% to 0 to disable rotation - default is 0 - {crash_log_size, 10485760}, - %% What time to rotate the crash log - default is no time - %% rotation. See the README for a description of this format. - {crash_log_date, "$D0"}, - %% Number of rotated crash logs to keep, 0 means keep only the - %% current one - default is 0 - {crash_log_count, 5}, - %% Whether to redirect error_logger messages into lager - defaults to true - {error_logger_redirect, true}, + {kernel, [ + %% 设置 Logger 的 primary log level + {logger_level, debug}, + {logger, [ + {handler, default, logger_std_h, + #{ + level => debug, + formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}} + } + }, - %% How big the gen_event mailbox can get before it is switched into sync mode - {async_threshold, 20}, - %% Switch back to async mode, when gen_event mailbox size decrease from `async_threshold' - %% to async_threshold - async_threshold_window - {async_threshold_window, 5}, + {handler, disk, logger_disk_log_h, + #{ + level => debug, + config => #{ + file => "log/debug.log", + max_no_files => 10, + max_no_bytes => 524288000 + }, + formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}} + } + } - {handlers, [ - %% debug | info | warning | error, 日志级别 - {lager_console_backend, debug}, - {lager_file_backend, [{file, "debug.log"}, {level, debug}, {size, 314572800}]}, - {lager_file_backend, [{file, "notice.log"}, {level, notice}, {size, 314572800}]}, - {lager_file_backend, [{file, "error.log"}, {level, error}, {size, 314572800}]}, - {lager_file_backend, [{file, "info.log"}, {level, info}, {size, 314572800}]} ]} ]} ]. diff --git a/config/sys-prod.config b/config/sys-prod.config index c798636..86a66ce 100644 --- a/config/sys-prod.config +++ b/config/sys-prod.config @@ -62,37 +62,29 @@ ]}, %% 系统日志配置,系统日志为lager, 支持日志按日期自动分割 - {lager, [ - {colored, true}, - %% Whether to write a crash log, and where. Undefined means no crash logger. - {crash_log, "trade_hub.crash.log"}, - %% Maximum size in bytes of events in the crash log - defaults to 65536 - {crash_log_msg_size, 65536}, - %% Maximum size of the crash log in bytes, before its rotated, set - %% to 0 to disable rotation - default is 0 - {crash_log_size, 10485760}, - %% What time to rotate the crash log - default is no time - %% rotation. See the README for a description of this format. - {crash_log_date, "$D0"}, - %% Number of rotated crash logs to keep, 0 means keep only the - %% current one - default is 0 - {crash_log_count, 5}, - %% Whether to redirect error_logger messages into lager - defaults to true - {error_logger_redirect, true}, + {kernel, [ + %% 设置 Logger 的 primary log level + {logger_level, debug}, + {logger, [ + {handler, default, logger_std_h, + #{ + level => debug, + formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}} + } + }, - %% How big the gen_event mailbox can get before it is switched into sync mode - {async_threshold, 20}, - %% Switch back to async mode, when gen_event mailbox size decrease from `async_threshold' - %% to async_threshold - async_threshold_window - {async_threshold_window, 5}, + {handler, disk, logger_disk_log_h, + #{ + level => debug, + config => #{ + file => "log/debug.log", + max_no_files => 10, + max_no_bytes => 524288000 + }, + formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}} + } + } - {handlers, [ - %% debug | info | warning | error, 日志级别 - {lager_console_backend, debug}, - {lager_file_backend, [{file, "debug.log"}, {level, debug}, {size, 314572800}]}, - {lager_file_backend, [{file, "notice.log"}, {level, notice}, {size, 314572800}]}, - {lager_file_backend, [{file, "error.log"}, {level, error}, {size, 314572800}]}, - {lager_file_backend, [{file, "info.log"}, {level, info}, {size, 314572800}]} ]} ]} ]. diff --git a/rebar.lock b/rebar.lock index 6fb10ed..e43e3d7 100644 --- a/rebar.lock +++ b/rebar.lock @@ -54,10 +54,15 @@ {git,"https://github.com/devinus/poolboy.git", {ref,"3bb48a893ff5598f7c73731ac17545206d259fac"}}, 0}, + {<<"quicer">>, + {git,"https://github.com/emqx/quic.git", + {ref,"c2962fd732caa29d513de7c645ea307cf89aaa9c"}}, + 0}, {<<"ranch">>, {git,"https://github.com/ninenines/ranch", {ref,"a692f44567034dacf5efcaa24a24183788594eb7"}}, 1}, + {<<"snabbkaffe">>,{pkg,<<"snabbkaffe">>,<<"1.0.10">>},1}, {<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.6">>},1}, {<<"sync">>, {git,"https://github.com/rustyio/sync.git", @@ -77,6 +82,7 @@ {<<"idna">>, <<"1D038FB2E7668CE41FBF681D2C45902E52B3CB9E9C77B55334353B222C2EE50C">>}, {<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>}, {<<"mimerl">>, <<"67E2D3F571088D5CFD3E550C383094B47159F3EEE8FFA08E64106CDF5E981BE3">>}, + {<<"snabbkaffe">>, <<"9BE2F54F61FC6862391B666B2B5B76C3FA53598E2989A17CEF1B48CF347A8A63">>}, {<<"ssl_verify_fun">>, <<"CF344F5692C82D2CD7554F5EC8FD961548D4FD09E7D22F5B62482E5AEAEBD4B0">>}, {<<"unicode_util_compat">>, <<"8516502659002CEC19E244EBD90D312183064BE95025A319A6C7E89F4BCCD65B">>}]}, {pkg_hash_ext,[ @@ -87,6 +93,7 @@ {<<"idna">>, <<"A02C8A1C4FD601215BB0B0324C8A6986749F807CE35F25449EC9E69758708122">>}, {<<"metrics">>, <<"69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16">>}, {<<"mimerl">>, <<"F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323">>}, + {<<"snabbkaffe">>, <<"70A98DF36AE756908D55B5770891D443D63C903833E3E87D544036E13D4FAC26">>}, {<<"ssl_verify_fun">>, <<"BDB0D2471F453C88FF3908E7686F86F9BE327D065CC1EC16FA4540197EA04680">>}, {<<"unicode_util_compat">>, <<"D48D002E15F5CC105A696CF2F1BBB3FC72B4B770A184D8420C8DB20DA2674B38">>}]} ].