simple-log
1 API
sl-def-log
sl-log-to
sl-log-to-file
sl-log-to-display
sl-log-to-file&display
sl-set-log-level
sl-log-level
2 Generated procedures
9.1

simple-log🔗ℹ

Hans Dijkema <hans@dijkewijk.nl>

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

syntax

(sl-def-log id)

(sl-def-log id name)
(sl-def-log id name parent)
Defines a logger with topic 'id and creates:

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

syntax

(sl-log-to name callback)

Registers callback under the symbolic name derived from name.

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)

  • timestampYYYY-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?
Registers a callback that writes log lines to filename. The file is opened with 'replace.

Format:

"<topic>:<level>:<timestamp>:<message>"

procedure

(sl-log-to-display)  void?

Registers a callback that writes log lines to the current output port using displayln.

Format:

"<topic>:<level>:<timestamp>:<message>"

procedure

(sl-log-to-file&display filename)  void?

  filename : path-string?
Equivalent to combining sl-log-to-display and sl-log-to-file.

procedure

(sl-set-log-level l)  symbol?

  l : 
(or/c 'debug 'dbg
      'info
      'warning 'warn
      'error 'err
      'fatal)
Sets the module-wide log level and returns the normalized symbol.

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?

Returns the current module-wide log level (default 'debug).

2 Generated procedures🔗ℹ

A call to sl-def-log creates five procedures. For example:

(sl-def-log my-module)

creates:

procedure

(dbg-my-module msg arg ...)  void?

  msg : string?
  arg : any/c
Debug log.

procedure

(info-my-module msg arg ...)  void?

  msg : string?
  arg : any/c
Info log.

procedure

(warn-my-module msg arg ...)  void?

  msg : string?
  arg : any/c
Warning log.

procedure

(err-my-module msg arg ...)  void?

  msg : string?
  arg : any/c
Error log.

procedure

(fatal-my-module msg arg ...)  void?

  msg : string?
  arg : any/c
Fatal log.

All use format and emit asynchronously.