simple-log
A small logging layer on top of Racket’s logger system. A log definition creates a logger plus five convenience procedures. Messages are formatted with format, timestamped, and dispatched asynchronously to the registered callbacks.
1 API
| (require "simple-log") | package: simple-log |
dbg-id
info-id
warn-id
err-id
fatal-id
Note. If name is given, id dbg-prefix, etc. will be generated instead of dbg-id, etc.
Each procedure has shape:
(proc msg arg ...)
The message is formatted via format and emitted with a timestamp (YYYY-MM-DDTHH:MM:SS) and topic 'id.
If parent is omitted, the #f is used as "parent logger".
A background thread is started that receives log events and forwards them to the registered callbacks.
name is an identifier (not a runtime value). It is converted at macro expansion time to a symbol and used as key in the callback registry.
Invocation shape:
(callback topic level timestamp message)
with:
topic — logger topic (symbol)
level — level (symbol)
timestamp — YYYY-MM-DDTHH:MM:SS
message — formatted string
An existing callback with the same name is replaced.
procedure
(sl-log-to-file filename) → void?
filename : path-string?
Format:
"<topic>:<level>:<timestamp>:<message>"
procedure
(sl-log-to-display) → void?
Format:
"<topic>:<level>:<timestamp>:<message>"
procedure
(sl-log-to-file&display filename) → void?
filename : path-string?
procedure
(sl-set-log-level l) → symbol?
l :
(or/c 'debug 'dbg 'info 'warning 'warn 'error 'err 'fatal)
Aliases:
'dbg → 'debug
'warn → 'warning
'err → 'error
Other values raise an exception.
Note: this value is stored globally. The receiver installed by sl-def-log itself operates at level 'debug.
procedure
(sl-log-level) → symbol?
2 Generated procedures
A call to sl-def-log creates five procedures. For example:
(sl-def-log my-module)
creates:
All use format and emit asynchronously.