Copyright © 2014-2016 Takeru Ohta <phjgt308@gmail.com>
Behaviours: logi_filter.
A built-in stateless filter which filters log messages by an arbitrary user defined function
This module is mainly supposed to be used for ddebugging/testing purposes.
If you want to set a particular filter to a lot of logger instances, it is recommended to define a specified filter for efficiency reasons.
> error_logger:tty(false). % Suppresses annoying warning outputs for brevity
> Sink = logi_builtin_sink_fun:new(foo, fun (_, Format, Data) -> io:format(Format ++ "\n", Data) end).
> {ok, _} = logi_channel:install_sink(Sink, info).
> FilterFun = fun (C) -> not maps:get(discard, logi_context:get_metadata(C), false) end.
> Logger = logi:new([{filter, logi_builtin_filter_fun:new(FilterFun)}]).
> logi:save_as_default(Logger).
> logi:info("hello world", [], [{metadata, #{discard => false}}]). % passed
hello world
> logi:info("hello world", [], [{metadata, #{discard => true}}]). % discarded
% No output: the log message was discarded by the filter
filter_fun() = fun((logi_context:context()) -> boolean())
A log messages filter function
new/1 | Creates a filter which filters log messages by FilterFun |
new(FilterFun::filter_fun()) -> logi_filter:filter()
Creates a filter which filters log messages by FilterFun
Generated by EDoc