File lager-3.2.0-git.patch of Package lager
diff --git a/rebar.config b/rebar.config
index 77272c7..278df9c 100644
--- a/rebar.config
+++ b/rebar.config
@@ -40,9 +40,12 @@
{eunit_opts, [verbose]}.
{eunit_compile_opts, [
+ export_all,
+
nowarn_untyped_record,
nowarn_export_all
]}.
+
{deps, [
{goldrush, ".*", {git, "git://github.com/DeadZen/goldrush.git", {tag, "0.1.8"}}}
]}.
@@ -53,4 +56,3 @@
{cover_enabled, true}.
{edoc_opts, [{stylesheet_file, "./priv/edoc.css"}]}.
-{eunit_opts, [verbose]}.
diff --git a/src/lager_app.erl b/src/lager_app.erl
index 8f1464d..b76da53 100644
--- a/src/lager_app.erl
+++ b/src/lager_app.erl
@@ -23,6 +23,7 @@
-behaviour(application).
-include("lager.hrl").
-ifdef(TEST).
+-compile([export_all]).
-include_lib("eunit/include/eunit.hrl").
-endif.
-export([start/0,
@@ -138,11 +139,10 @@ maybe_install_sink_killer(_Sink, HWM, ReinstallTimer) ->
error_logger:error_msg("Invalid value for 'killer_hwm': ~p or 'killer_reinstall_after': ~p", [HWM, ReinstallTimer]),
throw({error, bad_config}).
-start_error_logger_handler({ok, false}, _HWM, _Whitelist) ->
+-spec start_error_logger_handler(boolean(), pos_integer(), list()) -> list().
+start_error_logger_handler(false, _HWM, _Whitelist) ->
[];
-start_error_logger_handler(_, HWM, undefined) ->
- start_error_logger_handler(ignore_me, HWM, {ok, []});
-start_error_logger_handler(_, HWM, {ok, WhiteList}) ->
+start_error_logger_handler(true, HWM, WhiteList) ->
GlStrategy = case application:get_env(lager, error_logger_groupleader_strategy) of
undefined ->
handle;
@@ -200,13 +200,16 @@ configure_extra_sinks(Sinks) ->
lists:foreach(fun({Sink, Proplist}) -> configure_sink(Sink, Proplist) end,
Sinks).
+-spec get_env(atom(), atom()) -> term().
get_env(Application, Key) ->
get_env(Application, Key, undefined).
+
%% R15 doesn't know about application:get_env/3
+-spec get_env(atom(), atom(), term()) -> term().
get_env(Application, Key, Default) ->
- get_env_default(application:get_env(Application, Key),
- Default).
+ get_env_default(application:get_env(Application, Key), Default).
+-spec get_env_default('undefined' | {'ok', term()}, term()) -> term().
get_env_default(undefined, Default) ->
Default;
get_env_default({ok, Value}, _Default) ->
@@ -235,9 +238,9 @@ boot() ->
lager:update_loglevel_config(?DEFAULT_SINK),
SavedHandlers = start_error_logger_handler(
- get_env(lager, error_logger_redirect),
- interpret_hwm(get_env(lager, error_logger_hwm)),
- get_env(lager, error_logger_whitelist)
+ get_env(lager, error_logger_redirect, true),
+ interpret_hwm(get_env(lager, error_logger_hwm, 0)),
+ get_env(lager, error_logger_whitelist, [])
),
SavedHandlers.
diff --git a/src/lager_handler_watcher.erl b/src/lager_handler_watcher.erl
index d5fe140..4e595e4 100644
--- a/src/lager_handler_watcher.erl
+++ b/src/lager_handler_watcher.erl
@@ -178,12 +178,10 @@ reinstall_on_runtime_failure_test_() ->
try
?assert(lists:member(lager_crash_backend, gen_event:which_handlers(lager_event))),
timer:sleep(6000),
- _ = lager_test_backend:pop(), %% throw away application start up message
- _ = lager_test_backend:pop(), %% throw away gen_event crash message
- {_Severity, _Date, Msg, _Metadata} = lager_test_backend:pop(),
- ?assertEqual("Lager event handler lager_crash_backend exited with reason crash", lists:flatten(Msg)),
- {_Severity2, _Date2, Msg2, _Metadata2} = lager_test_backend:pop(),
- ?assertMatch("Lager failed to install handler lager_crash_backend into lager_event, retrying later :"++_, lists:flatten(Msg2)),
+
+ pop_until("Lager event handler lager_crash_backend exited with reason crash", fun lists:flatten/1),
+ pop_until("Lager failed to install handler lager_crash_backend into lager_event, retrying later",
+ fun(Msg) -> string:substr(lists:flatten(Msg), 1, 84) end),
?assertEqual(false, lists:member(lager_crash_backend, gen_event:which_handlers(lager_event)))
after
application:stop(lager),
@@ -194,5 +192,17 @@ reinstall_on_runtime_failure_test_() ->
]
}.
+pop_until(String, Fun) ->
+ try_backend_pop(lager_test_backend:pop(), String, Fun).
+
+try_backend_pop(undefined, String, _Fun) ->
+ throw("Not found: " ++ String);
+try_backend_pop({_Severity, _Date, Msg, _Metadata}, String, Fun) ->
+ case Fun(Msg) of
+ String ->
+ ok;
+ _ ->
+ try_backend_pop(lager_test_backend:pop(), String, Fun)
+ end.
-endif.
diff --git a/src/lager_transform.erl b/src/lager_transform.erl
index 7648c46..8cea5a3 100644
--- a/src/lager_transform.erl
+++ b/src/lager_transform.erl
@@ -59,16 +59,19 @@ walk_ast(Acc, [{function, Line, Name, Arity, Clauses}|T]) ->
walk_ast([{function, Line, Name, Arity,
walk_clauses([], Clauses)}|Acc], T);
walk_ast(Acc, [{attribute, _, record, {Name, Fields}}=H|T]) ->
- FieldNames = lists:map(fun({record_field, _, {atom, _, FieldName}}) ->
- FieldName;
- ({record_field, _, {atom, _, FieldName}, _Default}) ->
- FieldName
- end, Fields),
+ FieldNames = lists:map(fun record_field_name/1, Fields),
stash_record({Name, FieldNames}),
walk_ast([H|Acc], T);
walk_ast(Acc, [H|T]) ->
walk_ast([H|Acc], T).
+record_field_name({record_field, _, {atom, _, FieldName}}) ->
+ FieldName;
+record_field_name({record_field, _, {atom, _, FieldName}, _Default}) ->
+ FieldName;
+record_field_name({typed_record_field, Field, _Type}) ->
+ record_field_name(Field).
+
walk_clauses(Acc, []) ->
lists:reverse(Acc);
walk_clauses(Acc, [{clause, Line, Arguments, Guards, Body}|T]) ->
diff --git a/test/lager_app_tests.erl b/test/lager_app_tests.erl
new file mode 100644
index 0000000..80fe985
--- /dev/null
+++ b/test/lager_app_tests.erl
@@ -0,0 +1,22 @@
+-module(lager_app_tests).
+
+-compile([{parse_transform, lager_transform}]).
+
+-include_lib("eunit/include/eunit.hrl").
+
+
+get_env_default_test() ->
+ ?assertEqual(<<"Some">>, lager_app:get_env_default(undefined, <<"Some">>)),
+ ?assertEqual(<<"Value">>, lager_app:get_env_default({ok, <<"Value">>}, <<"Some">>)),
+ ok.
+
+get_env_test() ->
+ application:set_env(myapp, mykey1, <<"Value">>),
+
+ ?assertEqual(<<"Some">>, lager_app:get_env(myapp, mykey0, <<"Some">>)),
+ ?assertEqual(<<"Value">>, lager_app:get_env(myapp, mykey1, <<"Some">>)),
+
+ ?assertEqual(undefined, lager_app:get_env(myapp, mykey0)),
+ ?assertEqual(<<"Value">>, lager_app:get_env(myapp, mykey1)),
+ ok.
+