Module

loggit

src/loggit.pooka

Loggit 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

enum

Level

src/loggit.pooka:12
enum Level

OTP severity, from the least to the most severe.

variant

Debug

src/loggit.pooka:13
Level.Debug
variant

Info

src/loggit.pooka:14
Level.Info
variant

Notice

src/loggit.pooka:15
Level.Notice
variant

Warning

src/loggit.pooka:16
Level.Warning
variant

Error

src/loggit.pooka:17
Level.Error
variant

Critical

src/loggit.pooka:18
Level.Critical
variant

Alert

src/loggit.pooka:19
Level.Alert
variant

Emergency

src/loggit.pooka:20
Level.Emergency
enum

Colour

src/loggit.pooka:24
enum Colour

Auto checks the logging device and honours NO_COLOR and FORCE_COLOR=1.

variant

Auto

src/loggit.pooka:25
Colour.Auto
variant

Always

src/loggit.pooka:26
Colour.Always
variant

Never

src/loggit.pooka:27
Colour.Never
enum

ConsoleStyle

src/loggit.pooka:31
enum ConsoleStyle

Choose a short console line or include UTC time, fields and stack frames.

variant

Simple

src/loggit.pooka:32
ConsoleStyle.Simple
variant

Detailed

src/loggit.pooka:33
ConsoleStyle.Detailed
class

Frame

src/loggit.pooka:37
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.

field

module_name

src/loggit.pooka:38
module_name: String
INFERREDString
field

function_name

src/loggit.pooka:39
function_name: String
INFERREDString
field

arity

src/loggit.pooka:40
arity: Int
INFERREDInt
field

file

src/loggit.pooka:41
file: Option(String)
INFERREDOption(String)
field

line

src/loggit.pooka:42
line: Option(Int)
INFERREDOption(Int)
constructor

new

src/loggit.pooka:38
INFERREDfn(String, String, Int, Option(String), Option(Int)) -> loggit.Frame
class

Failure

src/loggit.pooka:46
class Failure(
  kind: String,
  reason: String,
  source: Option(#(String, Int)),
  frames: List(Frame)
)

A captured exception or exit with its original BEAM stack.

field

kind

src/loggit.pooka:47
kind: String
INFERREDString
field

reason

src/loggit.pooka:48
reason: String
INFERREDString
field

source

src/loggit.pooka:49
source: Option(#(String, Int))
INFERREDOption(#(String, Int))
field

frames

src/loggit.pooka:50
frames: List(Frame)
INFERREDList(loggit.Frame)
constructor

new

src/loggit.pooka:47
INFERREDfn(String, String, Option(#(String, Int)), List(loggit.Frame)) -> loggit.Failure
class

Event

src/loggit.pooka:55
class 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.

field

level

src/loggit.pooka:56
level: Level
INFERREDloggit.Level
field

message

src/loggit.pooka:57
message: String
INFERREDString
field

timestamp_us

src/loggit.pooka:58
timestamp_us: Int
INFERREDInt
field

origin

src/loggit.pooka:59
origin: Option(String)
INFERREDOption(String)
field

fields

src/loggit.pooka:60
fields: List(#(String, String))
INFERREDList(#(String, String))
field

failure

src/loggit.pooka:61
failure: Option(Failure)
INFERREDOption(loggit.Failure)
constructor

new

src/loggit.pooka:56
INFERREDfn(loggit.Level, String, Int, Option(String), List(#(String, String)), Option(loggit.Failure)) -> loggit.Event
class

SinkStats

src/loggit.pooka:65
class SinkStats(dropped: Int, failed: Int)

Counts events rejected at capacity and callbacks that failed.

field

dropped

src/loggit.pooka:65
dropped: Int
INFERREDInt
field

failed

src/loggit.pooka:65
failed: Int
INFERREDInt
constructor

new

src/loggit.pooka:65
INFERREDfn(Int, Int) -> loggit.SinkStats
function

set_level

src/loggit.pooka:171
set_level(level: Level) -> Result(Nil, String)
INFERREDfn(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.

Pooka
let assert Ok(_) = loggit.set_level(Level.Info)
function

install_console

src/loggit.pooka:180
install_console(colour: Colour) -> Result(Nil, String)
INFERREDfn(loggit.Colour) -> Result(Nil, String)

Install the short console formatter on OTP's default handler.

Pooka
let assert Ok(_) = loggit.install_console(Colour.Never)
function

install_console_with_style

src/loggit.pooka:189
install_console_with_style(colour: Colour, style: ConsoleStyle) -> Result(
  Nil,
  String
)
INFERREDfn(loggit.Colour, loggit.ConsoleStyle) -> Result(Nil, String)

Choose the console style while keeping the default handler's destination and filters.

Pooka
let assert Ok(_) = loggit.install_console_with_style(Colour.Auto, ConsoleStyle.Detailed)
function

log

src/loggit.pooka:207
log(level: Level, message: String, fields: List(#(String, String)))
INFERREDfn(loggit.Level, String, List(#(String, String))) -> Nil

Emit a structured event through OTP. Event fields override scoped fields with the same key.

Pooka
loggit.log(Level.Info, "request finished", [#("request_id", "req-7")])
function

debug

src/loggit.pooka:212
debug(message: String)
INFERREDfn(String) -> Nil

Trace a detail while investigating a problem.

function

info

src/loggit.pooka:217
info(message: String)
INFERREDfn(String) -> Nil

Record an ordinary application event.

function

warning

src/loggit.pooka:222
warning(message: String)
INFERREDfn(String) -> Nil

Mark a problem the application can continue past.

function

error

src/loggit.pooka:227
error(message: String)
INFERREDfn(String) -> Nil

Record an error message at the Logger boundary.

function

with_fields

src/loggit.pooka:238
with_fields(fields: List(#(String, String)), work: fn() -> a) -> a
INFERREDfn(List(#(String, String)), fn() -> a) -> a

Attach 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.

Pooka
loggit.with_fields([#("request_id", "req-7")], fn() { loggit.info("request served") })
function

attempt

src/loggit.pooka:248
attempt(work: fn() -> a) -> Result(a, Failure)
INFERREDfn(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.

Pooka
let assert Ok(42) = loggit.attempt(fn() { 42 })
function

report

src/loggit.pooka:256
report(message: String, failure: Failure, fields: List(#(String, String)))
INFERREDfn(String, loggit.Failure, List(#(String, String))) -> Nil

Send a captured failure as an error event with optional request context.

function

subscribe

src/loggit.pooka:281
subscribe(
  minimum: Level,
  capacity: Int,
  collect: fn(Event) -> Nil
) -> Result(Nil, String)
INFERREDfn(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.

Pooka
let assert Ok(_) = loggit.subscribe(Level.Error, 64, fn(event) { loggit.debug(event.message) })
function

sink_stats

src/loggit.pooka:300
sink_stats() -> Result(SinkStats, String)
INFERREDfn() -> Result(loggit.SinkStats, String)

Read the collector's overload and callback failure totals.

function

flush

src/loggit.pooka:313
flush(timeout_ms: Int) -> Result(Nil, String)
INFERREDfn(Int) -> Result(Nil, String)

Wait for events already sent from this process to reach the collector. Producers in other processes may still be logging.

Pooka
let assert Ok(_) = loggit.flush(1000)
function

unsubscribe

src/loggit.pooka:318
unsubscribe() -> Result(Nil, String)
INFERREDfn() -> Result(Nil, String)

Remove the collector handler. Flush first if you need to wait for delivery.