logi_ex v0.1.1 Logi.BuiltIn.Filter.Fun
A built-in stateless filter which filters log messages by an arbitrary user defined function.
Behaviours: Logi.Filter
Note
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.
Examples
iex> sink = Logi.BuiltIn.Sink.Fun.new(:foo, fn (_, msg, _) -> IO.puts(msg) end)
iex> {:ok, _} = Logi.Channel.install_sink(sink, :info)
iex> filter_fun = fn (c) -> not Map.get(Logi.Context.get_metadata(c), :discard, false) end
iex> logger = Logi.new([filter: Logi.BuiltIn.Filter.Fun.new(filter_fun)])
iex> Logi.save_as_default logger
iex> require Logi
iex> Logi.info "hello world", [], [metadata: %{:discard => false}] # passed
#OUTPUT# hello world
iex> Logi.info "hello world", [], [metadata: %{:discard => true}] # discarded
# No output: the log message was discarded by the filter
Summary
Types
A log messages filter function
Functions
Creates a filter which filters log messages by filter_fun
Types
A log messages filter function.
Functions
Creates a filter which filters log messages by filter_fun
.