log

The log library provides a unified logging interface shared by core libraries and apps.

Log Levels

A log level is a symbol which may be used as the value of the *log-level* variable, which determines the current level of verbosity.

All possible values of *log-level* are stored in the *log-levels* variable:

*log-levels*
T :TRACE :DEBUG :INFO :WARN :ERROR :FATAL NIL

Note that the actual position of log-levels in the *log-level* vector implies the precedence of that level. For example :trace has the lowest precedence, and will not be printed unless the *log-level* is either :trace or t. :fatal hash the highest precence and will always be printed unless *log-level* is eql to nil.

Loggers

The logger class implements the multi-threaded object-based logging protocol which is built atop the std/pipe protocol.

(documentation 'logger 'type)
A class which implements logging functionality. An instance of this class may
be designated as the 'global' logger by setting the value of *LOGGER*, or may
be implemented for a specific application.
(sb-mop:class-direct-superclasses (find-class 'logger))
(#<STANDARD-CLASS STD/PIPE:PIPE>)

The global *logger* variable defaults to nil - it is up to the user to build a logger instance and start it. When there is no global logger set, the Logging Functions will print to *trace-output* directly while still respecting the *log-level*.

Configuration

When setting up logging for your application, it is recommended to subclass the logger-config class, which implements the obj/config protocol.

(describe (default-logger-config))
#<LOG:LOGGER-CONFIG {121AC915E3}>
  [standard-object]

Slots with :INSTANCE allocation:
  AST                            = ((LEVEL-FILTER :ID :LEVEL-FILTER :LEVEL :INFO)..
  SIZE                           = 10
  LEVEL                          = :INFO

The ast slot stores an unevaluated pipe used to initialized the logger resulting from the build method.

(ast (default-logger-config))
((LEVEL-FILTER :ID :LEVEL-FILTER :LEVEL :INFO)
 (TAG-TREE-FILTER :ID :TAG-FILTER) (STREAM-SINK :ID :SINK))

Logging Functions

There are two logging functions to keep in mind for each log level - a predicate and a printer. Using the :info log-level as an example the predicate is info-p and the printer is info!.

The predicate functions accept no arguments and check the current precedence of *log-level*, returning t if the associated printer has an equal to or higher precedence than the current level and thus should print messages. For example the info-p function will return t when *log-level* is one of :info, :debug, :trace, or t.