Browse Source

Application env error_logger_format_raw to not reformat error_logger messages

pull/305/head
Daniil Fedotov 9 years ago
parent
commit
75e827a1bf
3 changed files with 11 additions and 6 deletions
  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 View File

@ -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 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 lager itself to be treated like a regular lager log call. To disable this, set
the lager application variable `error_logger_redirect` to `false`. 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 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 with use of `trunc_io`) to a "crash log" which can be referred to for further

+ 7
- 6
src/error_logger_lager_h.erl View File

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

+ 2
- 0
src/lager.app.src View File

@ -47,6 +47,8 @@
{error_logger_redirect, true}, {error_logger_redirect, true},
%% How many messages per second to allow from error_logger before we start dropping them %% How many messages per second to allow from error_logger before we start dropping them
{error_logger_hwm, 50}, {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 %% How big the gen_event mailbox can get before it is
%% switched into sync mode. This value only applies to %% switched into sync mode. This value only applies to
%% the default sink; extra sinks can supply their own. %% the default sink; extra sinks can supply their own.

Loading…
Cancel
Save