[Erlang] - lager

lager是Erlang自己的日志系统。
可以通过一下方式获取源码
1.git clone https://gitcode.com/erlang-lager/lager.git
2.https://github.com/erlang-lager/lager

整体框架

在这里插入图片描述

lager的配置

{application, lager,
 [
  {description, "Erlang logging framework"},
  {vsn, "3.9.2"},
  {modules, []},
  {applications, [
                  kernel,
                  stdlib,
                  goldrush
                 ]},
  {registered, [lager_sup, lager_event, lager_crash_log, lager_handler_watcher_sup]},
  {mod, {lager_app, []}},
  {env, [
            %% Note: application:start(lager) overwrites previously defined environment variables
            %%       thus declaration of default handlers is done at lager_app.erl

            %% What colors to use with what log levels
            {colored, false},
            {colors, [
              {debug,     "\e[0;38m" },
              {info,      "\e[1;37m" },
              {notice,    "\e[1;36m" },
              {warning,   "\e[1;33m" },
              {error,     "\e[1;31m" },
              {critical,  "\e[1;35m" },
              {alert,     "\e[1;44m" },
              {emergency, "\e[1;41m" }

            ]},

            %% Where to write the logs
            {log_root, "log"},
            %% Whether to write a crash log, and where. False means no crash logger.
            {crash_log, "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},
            %% Crash Log Rotator Module - default is lager_rotator_default
            {crash_log_rotator, lager_rotator_default},
            %% Whether to redirect error_logger messages into the default lager_event sink - defaults to true
            {error_logger_redirect, true},
            %% How many messages per second to allow from error_logger before we start dropping them(每秒的日志量)
            {error_logger_hwm, 50},
            %% How big the gen_event mailbox can get before it is
            %% switched into sync mode.  This value only applies to
            %% the default sink; extra sinks can supply their own.
            {async_threshold, 20},
            %% Switch back to async mode, when gen_event mailbox size
            %% decrease from `async_threshold' to async_threshold -
            %% async_threshold_window. This value only applies to the
            %% default sink; extra sinks can supply their own.
            {async_threshold_window, 5}
        ]},
  {licenses, ["Apache 2"]},
  {links, [{"Github", "https://github.com/erlang-lager/lager"}]}
 ]}.

lager.erl中为什么没有info(),error()等接口

使用的时候都是lager:info()这样去调用lager的接口,但是打开lager.erl却找不到对应的接口实现,这是因为使用了parse_transform 得到调用地方的行号,模块名,函数名等信息,在生成目标二进制时,编译器会调用lager_transform:parse_transform/2修改代码的abstract code 然后再进行编译,所以生成的beam文件并不是你代码的beam文件。

-compile([{parse_transform, lager_transform}]).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值