Module logi_builtin_filter_fun

A built-in stateless filter which filters log messages by an arbitrary user defined function.

Copyright © 2014-2016 Takeru Ohta <phjgt308@gmail.com>

Behaviours: logi_filter.

Description

A built-in stateless filter which filters log messages by an arbitrary user defined function

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.

EXAMPLE

  > 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
  

Data Types

filter_fun()

filter_fun() = fun((logi_context:context()) -> boolean())

A log messages filter function

Function Index

new/1Creates a filter which filters log messages by FilterFun

Function Details

new/1

new(FilterFun::filter_fun()) -> logi_filter:filter()

Creates a filter which filters log messages by FilterFun


Generated by EDoc