► |  | Reference: Racket

1 | Language Model
2 | Syntactic Forms
3 | Datatypes
4 | Structures
5 | Classes and Objects
6 | Units
7 | Contracts
8 | Pattern Matching
9 | Control Flow
10 | Concurrency
11 | Macros
12 | Input and Output
13 | Reflection and Security
14 | Operating System
15 | Memory Management
16 | Unsafe Operations
17 | Running Racket
| Bibliography
| Index

▼ | 14 | Operating System

14.1 | Paths
14.2 | Filesystem
14.3 | Networking
14.4 | Processes
14.5 | Logging
14.6 | Time
14.7 | Environment and Runtime Information
14.8 | Command-Line Parsing

► | 14.5 | Logging

14.5.1 | Creating Loggers
14.5.2 | Logging Events
14.5.3 | Receiving Logged Events

On this page:

14.5.1`` Creating Loggers
logger?
make-logger
logger-name
current-logger
14.5.2`` Logging Events
log-message
log-level?
log-fatal
log-error
log-warning
log-info
log-debug
14.5.3`` Receiving Logged Events
log-receiver?
make-log-receiver

top ← prev up next →

#### 14.5`` Logging

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 the name (if any) 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 'info 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 should be "none", "fatal", "error", "warning", "info", or "debug".

  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 PLTSYSLOG.

  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.

##### 14.5.1`` Creating Loggers

( logger? v) → boolean?
v : any/c

Returns #t if v is a logger, #f otherwise.

( make-logger [name parent]) → logger?
name : ( or/c symbol? #f) = #f
parent : ( or/c logger? #f) = #f

Creates a new logger with an optional name and parent.

( logger-name logger) → ( or/c symbol? #f)
logger : logger?

Reports logger’s name, if any.

( current-logger ) → logger?
( current-logger logger) → void?
logger : logger?

A parameter that determines the current logger.

##### 14.5.2`` Logging Events

( log-message logger level message data) → void?
logger : logger?
level : ( or/c 'fatal 'error 'warning 'info 'debug)
message : string?
data : any/c

Reports an event to logger, which in turn distributes the information to any log receivers attached to logger or its ancestors that are interested in events at level or higher.

If logger has a name, then message is prefixed with the logger’s name followed by ": " before it is sent to receivers.

( log-level? logger level) → boolean?
logger : logger?
level : ( or/c 'fatal 'error 'warning 'info 'debug)

Reports whether any log receiver attached to logger or one of its ancestors is interested in level events (or potentially lower). Use this function to avoid work generating an event for log-message if no receiver is interested in the information; this shortcut is built into log-fatal, log-error, log-warning, log-info, and log-debug, however, so it should not be used with those forms.

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 string-expr)

( log-error string-expr)

( log-warning string-expr)

( log-info string-expr)

( log-debug string-expr)

Log an event with the current logger, evaluating string-expr only if the logger has receivers that are interested in the event. In addition, the current continuation’s continuation marks are sent to the logger with the message string.

For each log-level,

(log-level string-expr)

is equivalent to

( let ([l ( current-logger )])
( when ( log-level? l 'level)
( log-message l 'level string-expr
( current-continuation-marks ))))

##### 14.5.3`` Receiving Logged Events

( log-receiver? v) → boolean?
v : any/c

Returns #t if v is a log receiver, #f otherwise.

( make-log-receiver logger level) → log-receiver?
logger : logger?
level : ( or/c 'fatal 'error 'warning 'info 'debug)

Creates a log receiver to receive events of importance level and higher as reported to logger and its descendants.

A log receiver is a synchronizable event. It becomes ready as an synchronizable event when a logging event is received, so use sync to receive an logged event. The log receiver’s synchronization value is a vector containing three values: the level of the event as a symbol, an immutable string for the event message, and an arbitrary value that was supplied as the last argument to log-message when the event was logged.

top ← prev up next →