浏览代码

Merge branch 'master' of https://github.com/saleyn/lager into intg

pull/277/head
Mark Allen 10 年前
父节点
当前提交
d6cb3bf99f
共有 3 个文件被更改,包括 37 次插入21 次删除
  1. +3
    -1
      README.md
  2. +4
    -1
      src/lager_default_formatter.erl
  3. +30
    -19
      src/lager_util.erl

+ 3
- 1
README.md 查看文件

@ -192,7 +192,9 @@ Included is `lager_default_formatter`. This provides a generic, default formatt
* Any traditional iolist elements in the configuration are printed verbatim.
* Atoms in the configuration are treated as placeholders for lager metadata and extracted from the log message.
* The placeholders `date`, `time`, `message`, and `severity` will always exist.
* The placeholders `date`, `time`, `message`, `sev` and `severity` will always exist.
* `sev` is an abbreviated severity which is interpreted as a capitalized single letter encoding of the severity level
(e.g. `'debug'` -> `$D`)
* The placeholders `pid`, `file`, `line`, `module`, `function`, and `node` will always exist if the parse transform is used.
* Applications can define their own metadata placeholder.
* A tuple of `{atom(), semi-iolist()}` allows for a fallback for

+ 4
- 1
src/lager_default_formatter.erl 查看文件

@ -40,7 +40,7 @@
%% or refer to other properties, if desired. You can also use a {atom, semi-iolist(), semi-iolist()} formatter, which
%% acts like a ternary operator's true/false branches.
%%
%% The metadata properties date,time, message, and severity will always exist.
%% The metadata properties date,time, message, severity, and sev will always exist.
%% The properties pid, file, line, module, and function will always exist if the parser transform is used.
%%
%% Example:
@ -86,6 +86,9 @@ output(time,Msg) ->
T;
output(severity,Msg) ->
atom_to_list(lager_msg:severity(Msg));
output(sev,Msg) ->
%% Write brief acronym for the severity level (e.g. debug -> $D)
[lager_util:level_to_chr(lager_msg:severity(Msg))];
output(Prop,Msg) when is_atom(Prop) ->
Metadata = lager_msg:metadata(Msg),
make_printable(get_metadata(Prop,Metadata,<<"Undefined">>));

+ 30
- 19
src/lager_util.erl 查看文件

@ -18,7 +18,8 @@
-include_lib("kernel/include/file.hrl").
-export([levels/0, level_to_num/1, num_to_level/1, config_to_mask/1, config_to_levels/1, mask_to_levels/1,
-export([levels/0, level_to_num/1, level_to_chr/1,
num_to_level/1, config_to_mask/1, config_to_levels/1, mask_to_levels/1,
open_logfile/2, ensure_logfile/4, rotate_logfile/2, format_time/0, format_time/1,
localtime_ms/0, localtime_ms/1, maybe_utc/1, parse_rotation_date_spec/1,
calculate_next_rotation/1, validate_trace/1, check_traces/4, is_loggable/3,
@ -33,25 +34,35 @@
levels() ->
[debug, info, notice, warning, error, critical, alert, emergency, none].
level_to_num(debug) -> ?DEBUG;
level_to_num(info) -> ?INFO;
level_to_num(notice) -> ?NOTICE;
level_to_num(warning) -> ?WARNING;
level_to_num(error) -> ?ERROR;
level_to_num(critical) -> ?CRITICAL;
level_to_num(alert) -> ?ALERT;
level_to_num(emergency) -> ?EMERGENCY;
level_to_num(none) -> ?LOG_NONE.
num_to_level(?DEBUG) -> debug;
num_to_level(?INFO) -> info;
num_to_level(?NOTICE) -> notice;
num_to_level(?WARNING) -> warning;
num_to_level(?ERROR) -> error;
num_to_level(?CRITICAL) -> critical;
num_to_level(?ALERT) -> alert;
level_to_num(debug) -> ?DEBUG;
level_to_num(info) -> ?INFO;
level_to_num(notice) -> ?NOTICE;
level_to_num(warning) -> ?WARNING;
level_to_num(error) -> ?ERROR;
level_to_num(critical) -> ?CRITICAL;
level_to_num(alert) -> ?ALERT;
level_to_num(emergency) -> ?EMERGENCY;
level_to_num(none) -> ?LOG_NONE.
level_to_chr(debug) -> $D;
level_to_chr(info) -> $I;
level_to_chr(notice) -> $N;
level_to_chr(warning) -> $W;
level_to_chr(error) -> $E;
level_to_chr(critical) -> $C;
level_to_chr(alert) -> $A;
level_to_chr(emergency) -> $M;
level_to_chr(none) -> $ .
num_to_level(?DEBUG) -> debug;
num_to_level(?INFO) -> info;
num_to_level(?NOTICE) -> notice;
num_to_level(?WARNING) -> warning;
num_to_level(?ERROR) -> error;
num_to_level(?CRITICAL) -> critical;
num_to_level(?ALERT) -> alert;
num_to_level(?EMERGENCY) -> emergency;
num_to_level(?LOG_NONE) -> none.
num_to_level(?LOG_NONE) -> none.
-spec config_to_mask(atom()|string()) -> {'mask', integer()}.
config_to_mask(Conf) ->

正在加载...
取消
保存