Handlers Overview¶
A Handler receives (msg, extra, level) from a Logger, formats the message using
its own Formatter, and writes/transmits it somewhere.
Common Interface¶
Every handler built-in or custom must implement three methods to work with
Logger:addHandler():
| Method | Purpose |
|---|---|
:handle(msg, extra, level) |
Produce output (write to file, send over network, etc.) |
:format(msg, extra) |
Substitute {token} patterns using the formatter |
:addTo(logger) |
Insert self into logger.handlers (typically table.insert(logger.handlers, self)) |
addTo vs addHandler
You can add a handler to a logger with either handler:addTo(logger) or
logger:addHandler(handler). Both do table.insert(logger.handlers, self).
All Built-in Handlers¶
| Handler | Output | Page |
|---|---|---|
TerminalHandler |
Plain text to terminal or monitor | TerminalHandler |
ColoredTerminalHandler |
Per-level colored text with word-wrapping | ColoredTerminalHandler |
FileHandler |
Append to a file | FileHandler |
RotatingFileHandler |
File rotation by byte-size | RotatingFileHandler |
TimedRotatingFileHandler |
File rotation by time interval | TimedRotatingFileHandler |
WebsocketHandler |
Formatted string over websocket | WebsocketHandler |
RawWebsocketHandler |
Raw JSON {msg, extra} over websocket (no formatter) |
WebsocketHandler |
ModemHandler |
Formatted string over rednet/modem | ModemHandler |
RawModemHandler |
Raw {msg, extra} table over modem (no formatter) |
ModemHandler |
Related¶
- Architecture how handlers fit in the pipeline
- The Formatter how
{token}substitution works - Writing a Custom Handler build your own