(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
log-configure!procedureConfigure the logger incrementally. Only provided keys are changed.
Supported keywords:
level:— symbol ('trace,'debug,'info,'warn,'error,'fatal) or number (0-5)format:—'textor'jsontarget:—'console(stderr), an output port, or a file path stringmodules:— alist of(name . level)for per-module filtering
(log-configure! level: 'debug format: 'json)
(log-configure! target: (open-output-file "app.log"))log-level-active?procedureCheck 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 abovecurrent-log-levelprocedureReturn the current log level as a symbol.
(current-log-level) ; => 'info (default)log-traceprocedureLog a message at TRACE level (0).
(log-trace "entering function" name: "process-request")log-debugprocedureLog a message at DEBUG level (1).
(log-debug "cache hit" key: "user:42")log-infoprocedureLog a message at INFO level (2).
(log-info "Server started" port: 8080)log-warnprocedureLog a message at WARN level (3).
(log-warn "Slow query" duration-ms: 1200)log-errorprocedureLog a message at ERROR level (4).
(log-error "Request failed" path: "/api" status: 500)log-fatalprocedureLog a message at FATAL level (5).
(log-fatal "Cannot start" reason: "port in use")log-configure-from-args!procedureConfigure 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)