Module
loggit
src/loggit.pookaLoggit sends events to the node's Erlang/OTP Logger. A console formatter renders those events for people, while a separate handler delivers typed events to a collector. An error tracker can group stack frames and attach request fields without parsing the terminal.
API reference
- enumLevel
- enumColour
- enumConsoleStyle
- classFrame
- classFailure
- classEvent
- classSinkStats
- functionset_level
- functioninstall_console
- functioninstall_console_with_style
- functionlog
- functiondebug
- functioninfo
- functionwarning
- functionerror
- functionwith_fields
- functionattempt
- functionreport
- functionsubscribe
- functionsink_stats
- functionflush
- functionunsubscribe
enum Level
OTP severity, from the least to the most severe.
Level.Debug
Level.Info
Level.Notice
Level.Warning
Level.Error
Level.Critical
Level.Alert
Level.Emergency
enum Colour
Auto checks the logging device and honours NO_COLOR and FORCE_COLOR=1.
Colour.Auto
Colour.Always
Colour.Never
enum ConsoleStyle
Choose a short console line or include UTC time, fields and stack frames.
ConsoleStyle.Simple
ConsoleStyle.Detailed
class Frame(
module_name: String,
function_name: String,
arity: Int,
file: Option(String),
line: Option(Int)
)
One stack location. Foreign frames may lack a source file or line.
module_name: String
Stringfunction_name: String
Stringarity: Int
Intfile: Option(String)
Option(String)line: Option(Int)
Option(Int)
fn(String, String, Int, Option(String), Option(Int)) -> loggit.Frameclass Failure(
kind: String,
reason: String,
source: Option(#(String, Int)),
frames: List(Frame)
)
A captured exception or exit with its original BEAM stack.
kind: String
Stringreason: String
Stringsource: Option(#(String, Int))
Option(#(String, Int))frames: List(Frame)
List(loggit.Frame)
fn(String, String, Option(#(String, Int)), List(loggit.Frame)) -> loggit.Failureclass Event(
level: Level,
message: String,
timestamp_us: Int,
origin: Option(String),
fields: List(#(String, String)),
failure: Option(Failure)
)
A normalized Logger event. Timestamp is UTC microseconds since the epoch. Fields contain the explicit Loggit context and event fields.
level: Level
loggit.Levelmessage: String
Stringtimestamp_us: Int
Intorigin: Option(String)
Option(String)fields: List(#(String, String))
List(#(String, String))failure: Option(Failure)
Option(loggit.Failure)
fn(loggit.Level, String, Int, Option(String), List(#(String, String)), Option(loggit.Failure)) -> loggit.Eventclass SinkStats(dropped: Int, failed: Int)
Counts events rejected at capacity and callbacks that failed.
dropped: Int
Intfailed: Int
Int
fn(Int, Int) -> loggit.SinkStatsset_level(level: Level) -> Result(Nil, String)
fn(loggit.Level) -> Result(Nil, String)Set the minimum severity for the entire node. Startup code normally calls this once. A handler may choose a stricter threshold independently.
let assert Ok(_) = loggit.set_level(Level.Info)
install_console(colour: Colour) -> Result(Nil, String)
fn(loggit.Colour) -> Result(Nil, String)Install the short console formatter on OTP's default handler.
let assert Ok(_) = loggit.install_console(Colour.Never)
install_console_with_style(colour: Colour, style: ConsoleStyle) -> Result(
Nil,
String
)
fn(loggit.Colour, loggit.ConsoleStyle) -> Result(Nil, String)Choose the console style while keeping the default handler's destination and filters.
let assert Ok(_) = loggit.install_console_with_style(Colour.Auto, ConsoleStyle.Detailed)
log(level: Level, message: String, fields: List(#(String, String)))
fn(loggit.Level, String, List(#(String, String))) -> NilEmit a structured event through OTP. Event fields override scoped fields with the same key.
loggit.log(Level.Info, "request finished", [#("request_id", "req-7")])
debug(message: String)
fn(String) -> NilTrace a detail while investigating a problem.
info(message: String)
fn(String) -> NilRecord an ordinary application event.
warning(message: String)
fn(String) -> NilMark a problem the application can continue past.
error(message: String)
fn(String) -> NilRecord an error message at the Logger boundary.
with_fields(fields: List(#(String, String)), work: fn() -> a) -> a
fn(List(#(String, String)), fn() -> a) -> aAttach context for this process during a callback. Nested scopes merge their fields and restore the earlier context even if the callback raises. Pass request fields explicitly when work moves to a different process.
loggit.with_fields([#("request_id", "req-7")], fn() { loggit.info("request served") })
attempt(work: fn() -> a) -> Result(a, Failure)
fn(fn() -> a) -> Result(a, loggit.Failure)Catch a synchronous error, throw, or exit while preserving its stack. Use at a boundary where the caller can decide how to handle the failure.
let assert Ok(42) = loggit.attempt(fn() { 42 })
report(message: String, failure: Failure, fields: List(#(String, String)))
fn(String, loggit.Failure, List(#(String, String))) -> NilSend a captured failure as an error event with optional request context.
subscribe(
minimum: Level,
capacity: Int,
collect: fn(Event) -> Nil
) -> Result(Nil, String)
fn(loggit.Level, Int, fn(loggit.Event) -> Nil) -> Result(Nil, String)Start the node's Loggit collector. The callback runs on a dedicated process. It sees native OTP events too, subject to both Logger thresholds. At capacity, new events are dropped and counted. Capacity includes the event being handled. Install one collector per node.
let assert Ok(_) = loggit.subscribe(Level.Error, 64, fn(event) { loggit.debug(event.message) })
sink_stats() -> Result(SinkStats, String)
fn() -> Result(loggit.SinkStats, String)Read the collector's overload and callback failure totals.
flush(timeout_ms: Int) -> Result(Nil, String)
fn(Int) -> Result(Nil, String)Wait for events already sent from this process to reach the collector. Producers in other processes may still be logging.
let assert Ok(_) = loggit.flush(1000)
unsubscribe() -> Result(Nil, String)
fn() -> Result(Nil, String)Remove the collector handler. Flush first if you need to wait for delivery.