1 Exception utilities
2 Number utilities
3 String utilities
4 Bytes utilities
5 Symbol utilities
6 List utilities
7 PLT 4x hash utilities
8 PLT 3x hash utilities
9 Contract utilities
10 File and path utilities
11 Parameter utilities
12 Syntax utilities
13 SRFI19 time utilities
14 Generators
15 Generators (short names)
16 Pipelines
17 Write-through cache
18 Yieldable procedures
19 Debugging tools
20 Profiling tools
21 Logging tools
On this page:
log-stream
message-log
warning-log
error-log
current-log-preamble
with-log-preamble
current-log-port
with-log-port
log-generic
log-message
log-warning
log-error
Version: 3.99.0.23

 

21 Logging tools

 (require (planet untyped/unlib/log))

Utilities for simple logging of messages in an application-specific format.

(struct

 

log-stream

 

(name))

  name : symbol?

A structure representing a particular stream of log messages.

message-log : log-stream?

Default log stream for normal messages.

warning-log : log-stream?

Default log stream for warning messages.

error-log : log-stream?

Default log stream for error messages.

(current-log-preamble)  (-> list?)

(current-log-preamble preamble-ref)  void?

  preamble-ref : (-> list?)

Parameter for controlling the standard preamble printed with each log message. preamble-ref is thunk that returns a list of values to be included at the begining of each log message.

Examples:

  > (log-message "string" 123 'symbol)

  M,"string",123,symbol

  #(struct:tm:time time-tai 9210000 1210419135)

  > (parameterize ([current-log-preamble

                    (lambda () (list (current-inexact-milliseconds)))])

      (log-message "string" 123 'symbol)

      (log-message "string" 123 'symbol))

  M,1210419102922.949,"string",123,symbol

  M,1210419102922.994,"string",123,symbol

  #(struct:tm:time time-tai 9220000 1210419135)

(with-log-preamble thunk expr ...)

Syntactic shorthand for:

  (parameterize ([current-log-preamble thunk])

    expr ...)

(current-log-port)  (U output-port? (-> output-port?))

(current-log-port port+thunk)  void?

  port+thunk : (U output-port? (-> output-port?))

Parameter that controls the output-port to which to print log messages. port+thunk is either an output port or a thunk that returns an output port (useful, for example, for tying current-log-port to current-output-port or current-error-port).

(with-log-port port+thunk expr ...)

Syntactic shorthand for:

  (parameterize ([current-log-port port+thunk])

    expr ...)

(log-generic log args)  time?

  log : log-stream?

  args : list

Prints a message to log containing the stream name, the current-log-preamble and any args, and returns the current time as a SRFI 19 time structure.

Examples:

  > (log-generic message-log (list "string" 123 'symbol))

  M,"string",123,symbol

  #(struct:tm:time time-tai 9260000 1210419135)

  > (log-generic warning-log (list "string" 123 'symbol))

  W,"string",123,symbol

  #(struct:tm:time time-tai 9260000 1210419135)

  > (log-generic error-log (list "string" 123 'symbol))

  E,"string",123,symbol

  #(struct:tm:time time-tai 9270000 1210419135)

(log-message arg ...)  time?

  arg : any

Shorthand for (log-generic message-log (list any ...)).

(log-warning arg ...)  time?

  arg : any

Shorthand for (log-generic warning-log (list any ...)).

(log-error arg ...)  time?

  arg : any

Shorthand for (log-generic error-log (list any ...)).