由于公司需要将之前的error_logger升级为lager,过程中碰到一些问题,在这做个记录
升级过程
1. 将lager添加到项目的依赖中
2. 将lager配置添加到项目rebar.config中(整个项目都可以使用lager),
也可以添加到单独的模块中
3.将原有的error_logger替换成lager日志
4.重新编译代码
5.启动lager(可以在启动项目的同时启动lager)
6.lager的配置:一般在项目的app.config文件中进行配置
升级过程
1. 将lager添加到项目的依赖中
{deps, [
{'shared', ".*", { rsync, "../shared" } },
{'lager', ".*", { git, "git://github.com/basho/lager.git", "master" } },
{'pmap', ".*", { git, "git://github.com/slepher/pmap.git", "master" }},
{'espec', ".*", { git, "git://github.com/lucaspiller/espec.git", "master"} },
{'rebar_plugins', ".*", { git, "git://github.com/jacktang/rebar_plugins.git", "master"} },
{'amqp_client', ".*", { git, "https://github.com/jbrisbin/amqp_client.git", {tag, "rabbitmq_2.7.0"}}},
{'jsx', ".*", {git, "https://github.com/yuzhaoren/jsx.git", {branch, "beamspirit"}}}
]}.
2. 将lager配置添加到项目rebar.config中(整个项目都可以使用lager),
%% Erlang compiler options
{erl_opts, [ {parse_transform, lager_transform}]}.
也可以添加到单独的模块中
-compile([{parse_transform, lager_transform}]).
3.将原有的error_logger替换成lager日志
4.重新编译代码
./rebar clean compile
5.启动lager(可以在启动项目的同时启动lager)
lager:start()
6.lager的配置:一般在项目的app.config文件中进行配置
{lager, [
%% Whether to write a crash log, and where. Undefined means no crash logger.
{crash_log, "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},
%% 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},
{handlers, [
{lager_console_backend, [debug, true]},
{lager_file_backend, [
{"log/trade_hub.error.log", error, 10485760, "$D0", 5},
{"log/trade_hub.console.log", info, 10485760, "$D0", 5}
]}
]}
]}