瀏覽代碼

Application env error_logger_format_raw to not reformat error_logger messages

pull/305/head
Daniil Fedotov 9 年之前
父節點
當前提交
75e827a1bf
共有 3 個檔案被更改,包括 11 行新增6 行删除
  1. +2
    -0
      README.md
  2. +7
    -6
      src/error_logger_lager_h.erl
  3. +2
    -0
      src/lager.app.src

+ 2
- 0
README.md 查看文件

@ -222,6 +222,8 @@ Lager is also supplied with a `error_logger` handler module that translates
traditional erlang error messages into a friendlier format and sends them into
lager itself to be treated like a regular lager log call. To disable this, set
the lager application variable `error_logger_redirect` to `false`.
You can also disable reformating for OTP and Cowboy messages by setting variable
`error_logger_format_raw` to `true`.
The `error_logger` handler will also log more complete error messages (protected
with use of `trunc_io`) to a "crash log" which can be referred to for further

+ 7
- 6
src/error_logger_lager_h.erl 查看文件

@ -130,26 +130,27 @@ eval_gl(Event, State) ->
log_event(Event, #state{sink=Sink} = State) ->
case Event of
{error, _GL, {Pid, Fmt, Args}} ->
FormatRaw = application:get_env(lager, error_logger_format_raw, false),
case Fmt of
"** Generic server "++_ ->
{false, "** Generic server "++_} ->
%% gen_server terminate
[Name, _Msg, _State, Reason] = Args,
?CRASH_LOG(Event),
?LOGFMT(Sink, error, Pid, "gen_server ~w terminated with reason: ~s",
[Name, format_reason(Reason)]);
"** State machine "++_ ->
{false, "** State machine "++_} ->
%% gen_fsm terminate
[Name, _Msg, StateName, _StateData, Reason] = Args,
?CRASH_LOG(Event),
?LOGFMT(Sink, error, Pid, "gen_fsm ~w in state ~w terminated with reason: ~s",
[Name, StateName, format_reason(Reason)]);
"** gen_event handler"++_ ->
{false, "** gen_event handler"++_} ->
%% gen_event handler terminate
[ID, Name, _Msg, _State, Reason] = Args,
?CRASH_LOG(Event),
?LOGFMT(Sink, error, Pid, "gen_event ~w installed in ~w terminated with reason: ~s",
[ID, Name, format_reason(Reason)]);
"** Cowboy handler"++_ ->
{false, "** Cowboy handler"++_} ->
%% Cowboy HTTP server error
?CRASH_LOG(Event),
case Args of
@ -165,7 +166,7 @@ log_event(Event, #state{sink=Sink} = State) ->
"Cowboy handler ~p terminated in ~p:~p/~p with reason: ~s",
[Module, Module, Function, Arity, format_reason({Reason, StackTrace})])
end;
"Ranch listener "++_ ->
{false, "Ranch listener "++_} ->
%% Ranch errors
?CRASH_LOG(Event),
case Args of
@ -178,7 +179,7 @@ log_event(Event, #state{sink=Sink} = State) ->
"Ranch listener ~p terminated with reason: ~s",
[Ref, format_reason(Reason)])
end;
"webmachine error"++_ ->
{false, "webmachine error"++_} ->
%% Webmachine HTTP server error
?CRASH_LOG(Event),
[Path, Error] = Args,

+ 2
- 0
src/lager.app.src 查看文件

@ -47,6 +47,8 @@
{error_logger_redirect, true},
%% How many messages per second to allow from error_logger before we start dropping them
{error_logger_hwm, 50},
%% Whether to reformat OTP and Cowboy messages, or use format from event
{error_logger_format_raw, false},
%% 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.

Loading…
取消
儲存