From 75e827a1bf04735664d569d74b5ea22931e5aa23 Mon Sep 17 00:00:00 2001 From: Daniil Fedotov Date: Mon, 14 Dec 2015 18:04:51 +0000 Subject: [PATCH] Application env error_logger_format_raw to not reformat error_logger messages --- README.md | 2 ++ src/error_logger_lager_h.erl | 13 +++++++------ src/lager.app.src | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 47c4c7b..58770db 100644 --- a/README.md +++ b/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 diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index fc28934..5634b43 100644 --- a/src/error_logger_lager_h.erl +++ b/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, diff --git a/src/lager.app.src b/src/lager.app.src index a948a37..914cd0a 100644 --- a/src/lager.app.src +++ b/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.