sigildocs

(sigil log)

(sigil log) - Structured Logging

Provides structured logging with configurable levels, text and JSON output formats, and per-module filtering.

Usage: (import (sigil log))

(log-info "Server started" port: 8080) (log-warn "Slow query" duration-ms: 1200) (log-error "Request failed" path: "/api" status: 500)

;; Configure output (log-configure! level: 'debug format: 'json)

;; Lazy macros — expressions not evaluated if level inactive (log-debug* "result" value: (expensive-computation))

Exports

Configure the logger incrementally. Only provided keys are changed.

Supported keywords:

  • level: — symbol ('trace, 'debug, 'info, 'warn, 'error, 'fatal) or number (0-5)
  • format:'text or 'json
  • target:'console (stderr), an output port, or a file path string
  • modules: — alist of (name . level) for per-module filtering
(log-configure! level: 'debug format: 'json)
(log-configure! target: (open-output-file "app.log"))

Check whether a given log level is active.

Accepts a numeric level (0-5) or a symbol ('trace, 'debug, etc.). Returns #t if messages at that level would be emitted.

(log-level-active? 'debug)  ; => #t if level <= debug
(log-level-active? 1)       ; same as above

Return the current log level as a symbol.

(current-log-level)  ; => 'info (default)
log-traceprocedure

Log a message at TRACE level (0).

(log-trace "entering function" name: "process-request")
log-debugprocedure

Log a message at DEBUG level (1).

(log-debug "cache hit" key: "user:42")
log-infoprocedure

Log a message at INFO level (2).

(log-info "Server started" port: 8080)
log-warnprocedure

Log a message at WARN level (3).

(log-warn "Slow query" duration-ms: 1200)
log-errorprocedure

Log a message at ERROR level (4).

(log-error "Request failed" path: "/api" status: 500)
log-fatalprocedure

Log a message at FATAL level (5).

(log-fatal "Cannot start" reason: "port in use")

Configure logging from command-line arguments.

Scans the process arguments for --log <path> and --log-level <level>. When --log is found, configures the logger to write to that file. When --log-level is found, sets the level (trace, debug, info, warn, error, fatal). If --log-level is given without --log, logs to stderr.

Does nothing if neither flag is present.

;; In your app's main, before starting the server:
(log-configure-from-args!)
log-trace*variable

(No description)

log-debug*variable

(No description)

log-info*variable

(No description)

log-warn*variable

(No description)

log-error*variable

(No description)

log-fatal*variable

(No description)