logger_filters(3erl)
πΈ NAME πΈ
Okay bestie, welcome to logger_filters(3erl) β the Erlang Module Definition page for the logger_filters module. Filters to use with Logger. π
β¨ DESCRIPTION β¨
Every function exported from this module can be used as a primary filter or a handler filter. See logger:add_primary_filter/2 and logger:add_handler_filter/3 for more info on how filters get added.
Filters are removed with logger:remove_primary_filter/1 and logger:remove_handler_filter/2.
π EXPORTS π
π¦ domain(LogEvent, Extra) -> logger:filter_return() π¦
Types:
LogEvent = logger:log_event()
Extra = {Action, Compare, MatchDomain}
Action = log | stop
Compare = super | sub | equal | not_equal | undefined
MatchDomain = [atom()]
This filter is the way to filter log events based on a domain field in Metadata. That field is optional, and the whole point of using it is to group log events from, like, a specific functional area. That way a Logger handler can filter them or give them specialized treatment. β¨
A domain field has to be a list of atoms, and the domains get smaller and more specialized as the list grows longer. The greatest domain is [], which covers all possible domains. No cap.
For example, consider these domains:
D1 = [otp]
D2 = [otp, sasl]
D1 is the greatest of the two and is called a super-domain of D2. D2 is a sub-domain of D1. Both D1 and D2 are sub-domains of [].
The above domains are used for logs originating from Erlang/OTP. D1 means the log event comes from Erlang/OTP in general, and D2 means the log event is a so-called SASL report.
The Extra parameter to the domain/2 function is specified when you add the filter via logger:add_primary_filter/2 or logger:add_handler_filter/3.
The filter compares the value of the domain field in the log eventβs metadata (Domain) against MatchDomain. The filter matches if the value of Compare is:
sub: andDomainis equal to or a sub-domain ofMatchDomain, that is, ifMatchDomainis a prefix ofDomain. πsuper: andDomainis equal to or a super-domain ofMatchDomain, that is, ifDomainis a prefix ofMatchDomain. π¦equal: andDomainis equal toMatchDomain. β¨not_equal: andDomaindiffers fromMatchDomain, or if there is nodomainfield in metadata. πundefined: and there is nodomainfield in metadata. In this caseMatchDomainmust be set to[]. π
If the filter matches and Action is log, the log event is allowed. If the filter matches and Action is stop, the log event is stopped.
If the filter does not match, it returns ignore, meaning that other filters, or the value of the configuration parameter filter_default, decide if the event is allowed or not.
Log events that do not contain any domain field match only when Compare is equal to undefined or not_equal.
Example: stop all events with domain [otp, sasl | _] π
logger:set_handler_config(h1, filter_default, log). % this is the default
Filter = {fun logger_filters:domain/2, {stop, sub, [otp, sasl]}}.
logger:add_handler_filter(h1, no_sasl, Filter).
ok
π level(LogEvent, Extra) -> logger:filter_return() π
Types:
LogEvent = logger:log_event()
Extra = {Action, Operator, MatchLevel}
Action = log | stop
Operator = neq | eq | lt | gt | lteq | gteq
MatchLevel = logger:level()
This filter is the way to filter log events based on the log level. It matches log events by comparing the log level with a specified MatchLevel. π₯
The Extra parameter is specified when you add the filter via logger:add_primary_filter/2 or logger:add_handler_filter/3.
The filter compares the value of the eventβs log level (Level) to MatchLevel by calling logger:compare_levels(Level, MatchLevel). The filter matches if the value of Operator is:
neq: and the compare function returnsltorgt. πeq: and the compare function returnseq. πlt: and the compare function returnslt. π¦gt: and the compare function returnsgt. π₯lteq: and the compare function returnsltoreq. β¨gteq: and the compare function returnsgtoreq. π
If the filter matches and Action is log, the log event is allowed. If the filter matches and Action is stop, the log event is stopped.
If the filter does not match, it returns ignore, meaning that other filters, or the value of the configuration parameter filter_default, will decide if the event is allowed or not.
Example: only allow debug level log events π
logger:set_handler_config(h1, filter_default, stop).
Filter = {fun logger_filters:level/2, {log, eq, debug}}.
logger:add_handler_filter(h1, debug_only, Filter).
ok
π progress(LogEvent, Extra) -> logger:filter_return() π
Types:
LogEvent = logger:log_event()
Extra = log | stop
This filter matches all progress reports from supervisor and application_controller. π
If Extra is log, the progress reports are allowed. If Extra is stop, the progress reports are stopped.
The filter returns ignore for all other log events.
π§ remote_gl(LogEvent, Extra) -> logger:filter_return() π§
Types:
LogEvent = logger:log_event()
Extra = log | stop
This filter matches all events originating from a process that has its group leader on a remote node. π°οΈ
If Extra is log, the matching events are allowed. If Extra is stop, the matching events are stopped.
The filter returns ignore for all other log events.
π SEE ALSO π
π Big cute sign-off: this page is brought to you by Ericsson AB, version kernel 8.5.4.2, and the manual page is logger_filters(3erl). The footer doesnβt print a date, so no invented date bestie β just facts and vibes. π«Άβ¨
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms