1 Exception utilities
2 Number utilities
3 String utilities
4 Symbol utilities
5 SRFI19 time utilities
6 List
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 Generators
14 Generators (short names)
15 Pipelines
16 Write-through cache
17 Yieldable procedures
18 Debugging tools
19 Profiling tools
20 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

 

20 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 120000 1209976577)

  > (parameterize ([current-log-preamble

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

      (log-message "string" 123 'symbol)

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

  M,1209976544015.331,"string",123,symbol

  M,1209976544015.382,"string",123,symbol

  #(struct:tm:time time-tai 150000 1209976577)

(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

log-generic symbol (listof any) -> integer

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 "string" 123 'symbol)

  procedure log-generic: expects 2 arguments, given 4:

  #(struct:log-stream M) "string" 123 symbol

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

  procedure log-generic: expects 2 arguments, given 4:

  #(struct:log-stream W) "string" 123 symbol

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

  procedure log-generic: expects 2 arguments, given 4:

  #(struct:log-stream E) "string" 123 symbol

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