Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add documentation & function to clear all traces

  • Loading branch information...
commit 0e70e68841514a0d5ee3dff1a2014aee11a8b584 1 parent e3e8c80
Andrew Thompson Vagabond authored
Showing with 49 additions and 2 deletions.
  1. +42 −0
  2. +7 −2 src/lager.erl
@@ -156,3 +156,45 @@
[[][lager_syslog]]. It is packaged as a
separate application so Lager itself doesn't have an indirect dependancy on a
port driver. Please see the lager_syslog README for configuration information.
+* Tracing
+ Lager supports basic support for redirecting log messages based on log message
+ attributes. Lager automatically captures the module, function and line at the
+ log message callsite. However, you can add any additional attributes you wish:
+ lager:warning([{request, RequestID},{vhost, Vhost}], "Permission denied to ~s", [User])
+ Then, in addition to the default trace attributes, you'll be able to trace
+ based on request or vhost:
+ lager:trace_file("logs/", [{vhost, ""}], error)
+ You can also omit the final argument, and the loglevel will default to
+ 'debug'.
+ Tracing to the console is similar:
+ lager:trace_console([{request, 117}])
+ In the above example, the loglevel is omitted, but it can be specified as the
+ second argument if desired.
+ You can also specify multiple expressions in a filter, or use the '*' atom as
+ a wildcard to match any message that has that attribute, regardless of its
+ value.
+ Tracing to an existing logfile is also supported, if you wanted to log
+ warnings from a particular module to the default error.log:
+ lager:trace_file("log/error.log", [{module, mymodule}], warning)
+ To view the active log backends and traces, you can use the lager:status()
+ function. To clear all active traces, you can use lager:clear_all_traces().
9 src/lager.erl
@@ -23,7 +23,7 @@
%% API
log/8, log_dest/9, log/3, log/4,
- trace_file/2, trace_file/3, trace_console/1, trace_console/2,
+ trace_file/2, trace_file/3, trace_console/1, trace_console/2, clear_all_traces/0,
get_loglevel/1, set_loglevel/2, set_loglevel/3, get_loglevels/0,
minimum_loglevel/1, posix_error/1,
@@ -129,6 +129,10 @@ trace_console(Filter, Level) ->
+clear_all_traces() ->
+ {MinLevel, _Traces} = lager_mochiglobal:get(loglevel),
+ lager_mochiglobal:put(loglevel, {MinLevel, []}).
status() ->
Handlers = gen_event:which_handlers(lager_event),
Status = ["Lager status:\n",
@@ -145,7 +149,8 @@ status() ->
end || Handler <- Handlers],
"Active Traces:\n",
- io_lib:format("Tracing messages matching ~p at level ~p to ~p\n", [Filter, lager_util:num_to_level(Level), Destination])
+ io_lib:format("Tracing messages matching ~p at level ~p to ~p\n",
+ [Filter, lager_util:num_to_level(Level), Destination])
end || {Filter, Level, Destination} <- element(2, lager_mochiglobal:get(loglevel))]],
Please sign in to comment.
Something went wrong with that request. Please try again.