Logging
1 Overview
2 Definition
def-log
3 Logging functions
dbg-id
info-id
warn-id
err-id
fatal-id
4 Callbacks
log-to
5 Output helpers
log-to-display
log-to-file
9.1

Logging🔗

Hans Dijkema <hans@dijkewijk.nl>

 (require "simple-log") package: base

1 Overview🔗

Small wrapper around logger with per-logger callbacks.

A logger consists of a logger, a log-receiver (level 'debug), a mutable callback list, five logging procedures, and a background thread dispatching messages.

2 Definition🔗

syntax

(def-log id)

(def-log id parent)
Defines a logger id. If parent is omitted, (current-logger) is used.

Creates:

Starts a thread that syncs on the receiver and forwards messages to callbacks.

3 Logging functions🔗

procedure

(dbg-id msg arg ...)  void?

  msg : string?
  arg : any/c

procedure

(info-id msg arg ...)  void?

  msg : string?
  arg : any/c

procedure

(warn-id msg arg ...)  void?

  msg : string?
  arg : any/c

procedure

(err-id msg arg ...)  void?

  msg : string?
  arg : any/c

procedure

(fatal-id msg arg ...)  void?

  msg : string?
  arg : any/c

Formats with (apply format (cons msg args)) and calls log-message.

Attached data:

(list (iso-timestamp) 'id)

4 Callbacks🔗

syntax

(log-to id name callback)

Registers callback under name. Existing entry with same name is replaced.

Callback signature:

(λ (topic level dt msg) ...)

5 Output helpers🔗

syntax

(log-to-display id)

Registers 'display. Output:

topic:level:timestamp:message

syntax

(log-to-file id filename)

Registers 'file. File opened with #:exists 'replace. One line per message, flushed.