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 URL utilities
10 Contract utilities
11 File and path utilities
12 Parameter utilities
13 Syntax utilities
14 SRFI19 time utilities
15 Scribble utilities
16 Generators
17 Generators (short names)
18 Pipelines
19 Write-through cache
20 Yieldable procedures
21 Debugging tools
22 Profiling tools
23 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: 4.0.1.2

 

23 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 5220000 1215262893)

  > (parameterize ([current-log-preamble

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

      (log-message "string" 123 'symbol)

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

  M,1215262860526.076,"string",123,symbol

  M,1215262860526.135,"string",123,symbol

  #(struct:tm:time time-tai 5260000 1215262893)

(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 5310000 1215262893)

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

  W,"string",123,symbol

  #(struct:tm:time time-tai 5310000 1215262893)

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

  E,"string",123,symbol

  #(struct:tm:time time-tai 5320000 1215262893)

(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 ...)).