A logger accepts events that contain information to be logged for interested parties. A log receiver represents an interested party that receives logged events asynchronously. Each event has a level of importance, and a log receiver subscribes to logging events at a certain level of importance and higher. The levels, in decreasing order of importance, are 'fatal, 'error, 'warning, 'info, and 'debug.
To help organize logged events, loggers can be named and hierarchical. Every event reported to a logger is also propagated to its parent (if any), but the event message is prefixed with a name (if any) that is typically the name of the logger to which is was originally reported. A logger is not required to have a parent or name.
On start-up, Racket creates an initial logger that is used to record events from the core run-time system. For example, an 'debug event is reported for each garbage collection (see Garbage Collection). For this initial logger, two log receivers are also created: one that writes events to the process’s original error output port, and one that writes events to the system log. The level of written events in each case is system-specific, and the default can be changed through command-line flags (see Command Line) or through environment variables:
If the PLTSTDERR environment variable is defined and is not overridden by a command-line flag, it determines the level of the log receiver that propagates events to the original error port.
The environment variable’s value can be a ‹level›: none, fatal, error, warning, info, or debug; all events the corresponding level of higher are printed. After an initial ‹level›, the value can contain space-separated specifications of the form ‹level›@‹name›, which prints events whose names match ‹name› only at the given ‹level› or higher (where a ‹name› contains any character other than a space or @). For example, the value "error debug@GC" prints all events at the 'error level and higher, but prints events named 'GC at the 'debug level and higher (which includes all levels).
The default is "error".
If the PLTSYSLOG environment variable is defined and is not overridden by a command-line flag, it determines the level of the log receiver that propagates events to the system log. The possible values are the same as for PLTSTDERR.
The default is "none" for Unix or "error" for Windows and Mac OS X.
The current-logger parameter determines the current logger that is used by forms such as log-warning. On start-up, the initial value of this parameter is the initial logger. The run-time system sometimes uses the current logger to report events. For example, the bytecode compiler sometimes reports 'warning events when it detects an expression that would produce a run-time error if evaluated.
If notify-callback is provided, then it is called (under a continuation barrier) whenever an event is logged to the result logger or one of its descendants, but only if some log receiver is interested in the event in the same sense as log-level?. The event is not propagated to any log receivers until notify-callback returns.
(log-message logger level [ name] message data [ prefix-message?]) → void? logger : logger? level : (or/c 'fatal 'error 'warning 'info 'debug) name : (or/c symbol? #f) = (object-name logger) message : string? data : any/c prefix-message? : any/c = #t
Log receivers can filter events based on name. In addition, if name and prefix-message? are not #f, then message is prefixed with the name followed by ": " before it is sent to receivers.
Changed in version 188.8.131.52 of package base: Added the prefix-message? argument.
The result of this function can change if a garbage collection determines that a log receiver is no longer accessible (and therefore that any event information it receives will never become accessible).
(log-fatal format-string-expr v ...)
(log-error format-string-expr v ...)
(log-warning format-string-expr v ...)
(log-info format-string-expr v ...)
(log-debug format-string-expr v ...)
These form are convenient for using the current logger, but libraries
should generally use a specifically named logger—
For each log-level,
is equivalent to
(let ([l (current-logger)]) (when (log-level? l 'level) (log-message l 'level string-expr (current-continuation-marks))))
(log-level format-string-expr v ...)
is equivalent to
A log receiver is a synchronizable event. It becomes ready for synchronization when a logging event is received, so use sync to receive an logged event. The log receiver’s synchronization result is an immutable vector containing four values: the level of the event as a symbol, an immutable string for the event message, an arbitrary value that was supplied as the last argument to log-message when the event was logged, and a symbol or #f for the event name (where a symbol is usually the name of the original logger for the event).
Multiple pairs of level and name can be provided to indicate different specific levels for different names (where name defaults to #f only for the last given level). A level for a #f name applies only to events whose names do not match any other provided name. If the same name is provided multiple times, the level provided with the last instance in the argument list takes precedence.