For Gauche 0.9.15Search (procedure/syntax/module):

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

11.51 srfi.215 - Central log exchange

Module: srfi.215

This module abstracts a logging mechanism so that the code can produce log messages in the same way regardless of the underlying log system.

In Gauche, the default logging system is set to use gauche.logger (see gauche.logger - User-level logging). For Gauche-specific code, you can directly use gauche.logger. This module is convenient when you’re writing portable code.

Parameter: current-log-callback

[SRFI-215]{srfi.215} The value of this parameter must be a procedure that takes a single argument, a log message packet.

A log message packet is an alist, with symbols as keys. Their values can be a string, an exact integer, a bytevector (u8vector), or an instance of <error>. SRFI doesn’t specify what will happen if other types of values are given. Gauche converts them to strings before this callback is called, but a portable program should avoid passing values other than listed above.

Two keys, SEVERITY and MESSAGE, are always present, with an exact integer value and a string as their values, respectively. The severity value is between 0 and 7, inclusive, and corresponding constans are defined; see below. Users can use other keys freely, though SRFI-215 suggests some common key names so check them up.

SRFI-215 also suggests that the default log callback procedure buffers log messages, and pass them to a user-provided callback when this parameter is set/rebound. In our implementation, the default callback directly sends logs to log-format (see gauche.logger - User-level logging), for your convenience.

Parameter: current-log-fields

[SRFI-215]{srfi.215} This parameter holds a key-value list, (key1 value1 key2 value2 …), that are automatically appended to the fields passed to send-log. The effect is as if that procedure was always invoked as (apply send-log severity message key value ... (current-log-fields)).

When you set/rebind this parameter, the passed value is validated to be a valid key-value arguments for send-log.

Function: send-log severity message …

[SRFI-215]{srfi.215} A single-stop API to construct a log message packet and dispatch to the current log callback.

The severity argument must be an exact integer between 0 and 7, inclusive. It will be the value of SEVERITY key in the log message packet. There are constants defined for each severity value: EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, and DEBUG. The message argument is a string and will be the value of MESSAGE key in the log message packet.

The rest of the argument must be a key-value list. The SEVERITY and MESSAGE keys are prepended, and value of current-log-fields are appended, and the entire key-value list is converted to an alist to construct a log message packet. See current-log-callback above for the valid keys and values.

This procedure does not return a meaningful value.

(send-log INFO (string-append "User " username " logged in")
          'USERNAME username 'REMOTE_IP remote-ip)
Constant: EMERGENCY
Constant: ALERT
Constant: CRITICAL
Constant: ERROR
Constant: WARNING
Constant: NOTICE
Constant: INFO
Constant: DEBUG

[SRFI-215]{srfi.215} Bound to exact integers from 0 to 7, respectively, to indicate the severity of the incident to be logged.


Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]


For Gauche 0.9.15Search (procedure/syntax/module):