From df3cf1634507a53e17294469fbb945af0081faa2 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Wed, 21 Jan 2015 17:08:04 -0800 Subject: [PATCH] add application stop/start suppression for ct logs in common test, starting and stopping applications can make your logs very noisy. the patch allows these messages to be suppressed on the happy path, and raises the high water mark during ct tests so that messages aren't dropped. --- src/error_logger_lager_h.erl | 18 ++++++++++++++---- src/lager_common_test_backend.erl | 11 ++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index 321afc7..c557170 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -226,8 +226,13 @@ log_event(Event, State) -> Details = lists:sort(D), case Details of [{application, App}, {exited, Reason}, {type, _Type}] -> - ?LOGFMT(info, Pid, "Application ~w exited with reason: ~s", - [App, format_reason(Reason)]); + case application:get_env(lager, suppress_application_start_stop) of + {ok, true} when Reason == stopped -> + ok; + _ -> + ?LOGFMT(info, Pid, "Application ~w exited with reason: ~s", + [App, format_reason(Reason)]) + end; _ -> ?LOGMSG(info, Pid, print_silly_list(D)) end; @@ -237,8 +242,13 @@ log_event(Event, State) -> Details = lists:sort(D), case Details of [{application, App}, {started_at, Node}] -> - ?LOGFMT(info, P, "Application ~w started on node ~w", - [App, Node]); + case application:get_env(lager, suppress_application_start_stop) of + {ok, true} -> + ok; + _ -> + ?LOGFMT(info, P, "Application ~w started on node ~w", + [App, Node]) + end; [{started, Started}, {supervisor, Name}] -> MFA = format_mfa(get_value(mfargs, Started)), Pid = get_value(pid, Started), diff --git a/src/lager_common_test_backend.erl b/src/lager_common_test_backend.erl index 62e0c96..0e03d6f 100644 --- a/src/lager_common_test_backend.erl +++ b/src/lager_common_test_backend.erl @@ -40,10 +40,15 @@ bounce() -> bounce(Level) -> _ = application:stop(lager), - application:set_env(lager, handlers, [ - {lager_common_test_backend, [Level, false]} - ]), + application:set_env(lager, suppress_application_start_stop, true), + application:set_env(lager, handlers, + [ + {lager_common_test_backend, [Level, false]} + ]), ok = lager:start(), + %% we care more about getting all of our messages here than being + %% careful with the amount of memory that we're using. + error_logger_lager_h:set_high_water(100000), ok. -spec(init(integer()|atom()|[term()]) -> {ok, #state{}} | {error, atom()}).