Logger
Logger module: structured logging with levels and persistent context.
Log levels (ascending severity): Debug < Info < Warn < Error. The global level filter is set with set_level/1; messages below the current level are silently discarded.
with_context/2 attaches a key-value pair to every subsequent log entry. clear_context/0 removes all attached context.
Output goes to stderr in the format: [LEVEL] message {key=value, key2=value2}
Usage: Logger.set_level(Logger.Info) Logger.with_context("request_id", "abc123") Logger.info("handling request") Logger.warn("slow query") Logger.error("db connection lost") Logger.log_with(Logger.Info, "user signed in", [("user", "alice")])
Types
Functions
Parse a log level from a string (case-insensitive). Returns None for unknown strings.
Return the numeric rank of a log level: Debug=0, Info=1, Warn=2, Error=3.
Return true if level is at least as severe as min_level.
Format a log entry as a simple string: [LEVEL] message
Log at level only if level is enabled relative to min_level.
Set the minimum log level. Messages below this level are discarded.
Get the current minimum log level.
Add a key-value pair to the persistent log context.
Remove all persistent context key-value pairs.
Log a Debug-level message.
Log an Info-level message.
Log a Warn-level message.
Log an Error-level message.
Log a message at the given level.
Log a message at the given level with extra metadata. metadata is a List((String, String)) of key-value pairs.
Logger.log_with(Logger.Info, "request done", [("status", "200"), ("ms", "42")])