Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added options parameter to lager:trace_file #166

Merged
merged 1 commit into from

2 participants

@srstrong

I've added an additional (optional) parameter to lager:trace_file to allow the various lager_file_backend options to be passed in. The particular one I needed was to specify a rollover size, but this will work for all present and future options.

@Vagabond Vagabond merged commit 36466ef into basho:master

1 check failed

Details default The Travis CI build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 13, 2013
  1. @srstrong
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 6 deletions.
  1. +13 −6 src/lager.erl
  2. +12 −0 src/lager_file_backend.erl
View
19 src/lager.erl
@@ -26,7 +26,7 @@
-export([start/0,
log/3, log/4,
md/0, md/1,
- trace/2, trace/3, trace_file/2, trace_file/3, trace_console/1, trace_console/2,
+ trace/2, trace/3, trace_file/2, trace_file/3, trace_file/4, trace_console/1, trace_console/2,
clear_all_traces/0, stop_trace/1, status/0,
get_loglevel/1, set_loglevel/2, set_loglevel/3, get_loglevels/0,
update_loglevel_config/0, posix_error/1,
@@ -141,19 +141,26 @@ log(Level, Metadata, Format, Args) when is_list(Metadata) ->
dispatch_log(Level, Metadata, Format, Args, ?DEFAULT_TRUNCATION).
trace_file(File, Filter) ->
- trace_file(File, Filter, debug).
+ trace_file(File, Filter, debug, []).
-trace_file(File, Filter, Level) ->
+trace_file(File, Filter, Level) when is_atom(Level) ->
+ trace_file(File, Filter, Level, []);
+
+trace_file(File, Filter, Options) when is_list(Options) ->
+ trace_file(File, Filter, debug, Options).
+
+trace_file(File, Filter, Level, Options) ->
Trace0 = {Filter, Level, {lager_file_backend, File}},
case lager_util:validate_trace(Trace0) of
{ok, Trace} ->
Handlers = gen_event:which_handlers(lager_event),
%% check if this file backend is already installed
Res = case lists:member({lager_file_backend, File}, Handlers) of
- false ->
- %% install the handler
+ false ->
+ %% install the handler
+ LogFileConfig = lists:keystore(level, 1, lists:keystore(file, 1, Options, {file, File}), {level, none}),
supervisor:start_child(lager_handler_watcher_sup,
- [lager_event, {lager_file_backend, File}, {File, none}]);
+ [lager_event, {lager_file_backend, File}, LogFileConfig]);
_ ->
{ok, exists}
end,
View
12 src/lager_file_backend.erl
@@ -702,6 +702,18 @@ filesystem_test_() ->
{ok, Bin3} = file:read_file("foo.log"),
?assertMatch([_, _, "[error]", _, "Test message\n"], re:split(Bin3, " ", [{return, list}, {parts, 5}]))
end
+ },
+ {"tracing with options should work",
+ fun() ->
+ file:delete("foo.log"),
+ {ok, _} = lager:trace_file("foo.log", [{module, ?MODULE}], [{size, 20}, {check_interval, 1}]),
+ lager:error("Test message"),
+ lager:error("Test message"),
+ ?assertNot(filelib:is_regular("foo.log.0")),
+ lager:error("Test message"),
+ timer:sleep(10),
+ ?assert(filelib:is_regular("foo.log.0"))
+ end
}
]
}.
Something went wrong with that request. Please try again.