logger_handler(3)
π logger_handler β the manual, but make it make sense
okay bestie, gather round, because this one is literally the blueprint for every logger handler in Erlang. It lives in kernel, and the module name is logger_handler. That's the whole name. Short, sweet, iconic. π
β¨ NAME β¨
logger_handler β it's the behaviour module for logger handlers. Yes, behaviour with a u, we're fancy like that. π
πΈ DESCRIPTION πΈ
So here's the tea: logger_handler is the behaviour module for logger handlers. A logger handler is just a callback module β a little module full of callbacks β that gets called when a log event has passed all filters and is ready to be logged somewhere. Like, it survived the vibe check and now it gets to go live somewhere. β¨
For more info, go read Handlers in the Users Guide. That's where the lore lives.
π See Also
logger_filterslogger_formatterlogger
π DATA TYPES π
config()
config() ::
#{id => id(),
config => term(),
level => logger:level() | all | none,
module => module(),
filter_default => log | stop,
filters => [{logger:filter_id(), logger:filter()}],
formatter => {module(), logger:formatter_config()}}.
This is the handler configuration data for Logger. Here are the default values that just apply automatically, no questions asked:
level => allfilter_default => logfilters => []formatter => {logger_formatter, DefaultFormatterConfig}
And on top of those, Logger itself goes ahead and inserts these fields for you β the values come from the two first parameters you hand to logger:add_handler/3:
id => HandlerIdmodule => Module
β οΈ These two are read-only and cannot be changed in runtime. Not even a little. Don't try it. π
Handler-specific configuration data gets inserted by the handler callback itself, in a sub structure that hangs off the field named config. If you wanna know what those specific configs look like, go peek at the logger_std_h and logger_disk_log_h manual pages. π«Ά
And for the default configuration of this formatter? That's the logger_formatter manual page's job. Go say hi to it.
id()
id() :: atom().
A unique identifier for a handler instance. It's an atom, and it's that handler's name in the group chat. Only one of them can have it. π¦
olp_config()
olp_config() ::
#{sync_mode_qlen => non_neg_integer(),
drop_mode_qlen => pos_integer(),
flush_qlen => pos_integer(),
burst_limit_enable => boolean(),
burst_limit_max_count => pos_integer(),
burst_limit_window_time => pos_integer(),
overload_kill_enable => boolean(),
overload_kill_qlen => pos_integer(),
overload_kill_mem_size => pos_integer(),
overload_kill_restart_after => non_neg_integer() |
infinity}.
This is your overload protection configuration β literally the handler's bodyguards. π‘οΈ
Wanna know all the details? Go read Protecting the Handler from Overload. The full story is over there, no cap.
π¦ CALLBACKS π¦
adding_handler(Config1)
This one gets called on a temporary process when a new handler is about to be added. Its whole job is to verify the configuration and get all the resources the handler needs up and running. Basically the pre-game. β¨
The handler's identity is tied to the id key in Config1. That's how you know which handler you're dealing with.
If everything goes great? The callback can add any default values or internal state values it wants to the configuration, and then return the adjusted map as {ok,Config2}. Slay.
If the configuration is faulty, or the initiation just fails? The callback must return {error,Reason}. No hiding it. π
changing_config(SetOrUpdate, OldConfig, NewConfig)
Called on a temporary process when a handler's configuration is about to change. The vibe here is: verify the new config, and act on it. π
OldConfig is the existing configuration and NewConfig is the new one.
The handler identity is associated with the id key in OldConfig. (Yes, OldConfig, not NewConfig β read it again, bestie.)
Now, SetOrUpdate β this is the fun part:
- it has the value
setif the configuration change came from a call tologger:set_handler_config/2,3 - it has the value
updateif it came fromlogger:update_handler_config/2,3
The handler can use this parameter to decide how it updates the value of the config field β y'know, the handler-specific configuration data. Typically:
- if
SetOrUpdateequalsset, then values that are not specified must be given their default values - if
SetOrUpdateequalsupdate, then the values found inOldConfigmust be used instead
If everything works out, the callback must return a possibly adjusted configuration as {ok,Config}.
If the configuration is faulty, the callback must return {error,Reason}. Periodt. π
filter_config(Config)
This one gets called whenever one of the Logger API functions for fetching the handler configuration gets called β for example, logger:get_handler_config/1. πΈ
What's it for? It lets the handler remove internal data fields from its configuration data before that data gets handed back to whoever asked. Privacy settings, but for config. π
log(LogEvent, Config)
The moment we've all been waiting for. π This gets called when all primary filters and all handler filters for the handler in question have passed for the given log event.
Important: it's called on the client process β that is, the process that issued the log event. Not some background guy. The actual client.
The handler identity is associated with the id key in Config.
The handler must log the event. That's literally its whole purpose, bestie.
The return value from this function is ignored by Logger. So don't stress about it. β¨
removing_handler(Config)
Called on a temporary process when a handler is about to be removed. Its purpose: release all resources used by the handler. Clean up your room before you leave. π§Ή
The handler identity is associated with the id key in Config.
The return value is ignored by Logger. Again. Logger is not nosy about return values.
okay that's the whole page!! every callback, every field, every default, all of it, accounted for. π«Ά
this masterpiece was brought to you by Ericsson AB, from kernel 11.0.3, and it's the logger_handler(3) manual page β go forth and handle your logs, bestie, you're gonna eat π
β¨
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms