Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
[[tags: egg]] == logger Simple structured logging for CHICKEN Scheme with per-module level control. [[toc:]] === Description A lightweight logging library that provides: * Four log levels: {{debug}}, {{info}}, {{warn}}, {{error}} * Per-module log level control * Module-local logging functions via {{logger/install}} macro * Text and JSON output formats * Configurable output port * ISO 8601 timestamps === Author Rolando Abarca === Repository [[https://forgejo.rolando.cl/cpm/logger-egg]] === Requirements * [[srfi-1]] * [[medea]] === Documentation ==== Quick Start <enscript highlight="scheme"> (import logger) ;; Basic logging (uses GLOBAL module name) (logger/d "debug message") (logger/i "info message") (logger/w "warning message") (logger/e "error message") ;; Messages can be concatenated (logger/i "user " user-id " logged in") </enscript> Output: 2026-01-18T19:07:51Z [INFO] [GLOBAL] info message ==== Per-Module Logging Use {{logger/install}} inside a module to create local {{d}}, {{i}}, {{w}}, {{e}} functions that automatically tag logs with the module name: <enscript highlight="scheme"> (module my-app (do-stuff) (import scheme chicken.base logger) (logger/install my-app) (define (do-stuff) (i "doing stuff") ;; tagged as [my-app] (d "details..."))) </enscript> Output: 2026-01-18T19:07:51Z [INFO] [my-app] doing stuff 2026-01-18T19:07:51Z [DEBUG] [my-app] details... ==== API Reference ===== Parameters <parameter>logger/level</parameter> Global log level. Messages below this priority are suppressed. Default: {{'debug}}. Valid values: {{'debug}}, {{'info}}, {{'warn}}, {{'error}}, {{'none}} <enscript highlight="scheme"> ;; Set global level to info (hides debug messages) (logger/level 'info) ;; Get current level (logger/level) ; => 'info </enscript> <parameter>logger/output</parameter> Output port for log messages. Default: {{(current-output-port)}}. <enscript highlight="scheme"> (import chicken.file.posix) ;; Log to a file (define log-port (open-output-file "app.log")) (logger/output log-port) ;; Log to stderr (import chicken.port) (logger/output (current-error-port)) </enscript> <parameter>logger/format</parameter> Output format. Default: {{'text}}. ; {{'text}} : Human-readable format: {{TIMESTAMP [LEVEL] [MODULE] message}} ; {{'json}} : JSON format: {{{"ts":N,"level":"...","module":"...","message":"..."}}} <enscript highlight="scheme"> ;; Text format (default) (logger/format 'text) ;; Output: 2026-01-18T19:07:51Z [INFO] [GLOBAL] message ;; JSON format (logger/format 'json) ;; Output: {"ts":1737226071,"level":"info","module":"GLOBAL","message":"message"} </enscript> <parameter>logger/module-levels</parameter> Alist of per-module log levels. Use {{logger/set-module-level!}} to modify. ===== Procedures <procedure>(logger/log module-name level msg . rest)</procedure> Core logging function. Logs a message if {{level}} meets or exceeds the effective level for {{module-name}}. ; {{module-name}} : Symbol identifying the module. ; {{level}} : Log level symbol: {{'debug}}, {{'info}}, {{'warn}}, or {{'error}}. ; {{msg}} : Message string or value. ; {{rest}} : Additional values to concatenate to the message. <enscript highlight="scheme"> (logger/log 'my-module 'info "Processing item " item-id) </enscript> <procedure>(logger/d msg . rest)</procedure> <procedure>(logger/i msg . rest)</procedure> <procedure>(logger/w msg . rest)</procedure> <procedure>(logger/e msg . rest)</procedure> Convenience functions for logging at debug, info, warn, and error levels respectively. Uses {{'GLOBAL}} as the module name. <enscript highlight="scheme"> (logger/d "debug details") (logger/i "informational message") (logger/w "warning!") (logger/e "error occurred: " error-msg) </enscript> <procedure>(logger/set-module-level! module-name level)</procedure> Set the log level for a specific module. This overrides the global {{logger/level}} for that module. <enscript highlight="scheme"> ;; Only show warnings and errors from noisy-module (logger/set-module-level! 'noisy-module 'warn) ;; Show all messages from important-module even if global level is higher (logger/set-module-level! 'important-module 'debug) </enscript> <procedure>(logger/disable-module! module-name)</procedure> Disable all logging for a specific module. Equivalent to {{(logger/set-module-level! module-name 'none)}}. <enscript highlight="scheme"> (logger/disable-module! 'noisy-module) </enscript> ===== Macros <syntax>(logger/install module-name)</syntax> Installs module-local logging functions {{d}}, {{i}}, {{w}}, and {{e}} that automatically tag messages with {{module-name}}. Must be called at the top level of a module, after imports. <enscript highlight="scheme"> (module my-component (initialize shutdown) (import scheme chicken.base logger) (logger/install my-component) (define (initialize) (i "initializing...") (d "loading config")) (define (shutdown) (i "shutting down"))) </enscript> ==== Log Levels Levels from lowest to highest priority: ; {{debug}} : Detailed information for debugging. Priority: 0 ; {{info}} : General informational messages. Priority: 1 ; {{warn}} : Warning conditions. Priority: 2 ; {{error}} : Error conditions. Priority: 3 ; {{none}} : Disables logging entirely. Priority: 999 Messages are logged only if their level priority is greater than or equal to the effective level for the module. === Examples ==== Application with Multiple Modules <enscript highlight="scheme"> ;;; main.scm (import scheme chicken.base logger) (import my-db my-http) ;; Set global level to info (logger/level 'info) ;; But show debug messages from database module (logger/set-module-level! 'my-db 'debug) ;; Suppress http module unless errors (logger/set-module-level! 'my-http 'error) (db-connect "localhost") (http-serve 8080) </enscript> <enscript highlight="scheme"> ;;; my-db.scm (module my-db (db-connect) (import scheme chicken.base logger) (logger/install my-db) (define (db-connect host) (i "connecting to " host) (d "using default port 5432") ;; ... (i "connected"))) </enscript> <enscript highlight="scheme"> ;;; my-http.scm (module my-http (http-serve) (import scheme chicken.base logger) (logger/install my-http) (define (http-serve port) (i "starting server on port " port) ;; suppressed (d "debug info") ;; suppressed ;; ... )) </enscript> ==== JSON Logging for Production <enscript highlight="scheme"> (import logger chicken.file.posix) ;; Configure for production (logger/format 'json) (logger/level 'info) (logger/output (open-output-file "/var/log/myapp.log")) (logger/i "application started") ;; {"ts":1737226071,"level":"info","module":"GLOBAL","message":"application started"} </enscript> === License BSD-3-Clause === Version History ; 0.0.2 : Initial release.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 3 by 3?