error_logger升级到lager:erlang日志框架

由于公司需要将之前的error_logger升级为lager,过程中碰到一些问题,在这做个记录


升级过程
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}
                                           ]}
                     ]}
         ]}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值