logi_ex v0.1.1 Logi.Filter behaviour
Log Message Filter Behaviour.
A filter decides whether to allow a message be sent to the target channel.
Note
A filter should not raise exceptions when it’s filter/2 is called.
If any exception is raised, the invocation of the log function will be aborted and the exception will be propagated to the caller process.
Examples
iex> require Logi
iex> write = fn (_, format, data) -> :io.format format <> "\n", data end
iex> {:ok, _} = Logi.Channel.install_sink(Logi.BuiltIn.Sink.Fun.new(:foo, write), :info)
iex> filter = fn (context) -> not Map.get(Logi.Context.get_metadata(context), :discard, false) end
iex> logger = Logi.new([filter: Logi.BuiltIn.Filter.Fun.new(filter)])
iex> Logi.save_as_default logger
iex> Logi.info "hello world"
#OUTPUT# hello world
iex> Logi.info "hello world", [], [metadata: %{:discard => true}]
# No output: the log message was discarded by the filter
Summary
Types
A module that implements the Logi.Filter behaviour
An instance of Logi.Filter behaviour implementation module
Functions
Applies filter
Returns true if x is a filter/0 value, false otherwise
Gets the module of filter
Gets the state of filter
Creates a new filter instance
Callbacks
Log messages filtering function
Types
A module that implements the Logi.Filter behaviour.
An instance of Logi.Filter behaviour implementation module.
The value of the second arguemnt of the filter/2 callback function.
If a filter() does not have an explicit state(), nil will be passed instead.
Functions
apply(Logi.Context.context, filter) :: do_allow | {do_allow, new_filter} when do_allow: boolean, new_filter: filter
Applies filter.
This function returns do_allow if the state of filter is not changed, {do_allow, new_filter} otherwise.
Returns true if x is a filter/0 value, false otherwise.
Gets the module of filter.
Creates a new filter instance.
Callbacks
Log messages filtering function.
This function decides whether to allow a message be sent to the target channel.
If it returns false (or {false, state}), the message will be dropped.