Library
Module
Module type
Parameter
Class
Class type
Logging infrastructure inspired by the Python logging module. The aim of this module is to provide a quick and easy to use logging infrastructure.
It has the following features :
string
or string lazy_t
open Easy_logging
logger = Logging.make_logger "my_logger" (Some Debug) [Cli Debug];;
logger#info "log_message";;
will output to the stdout a message of the form
1.306 my_logger Info log_message
Easy_logging.Logging.logger
: Default logger class.Easy_logging__Default_handlers
: Default handlers.Easy_logging.MakeLogging
: Functor to create your own logging module.Easy_logging__Easy_logging_types
: Types definitions.Easy_logging
: Entry point of the module.Like in the python logging module, this logging infrastructure is based on four concepts:
loggers, handlers, formatters and log items.
A call to logger will create a log item, which it will pass to its handlers. Each handler transforms the log item to a string using its assigned formatter, and then treats the item (e.g. outputs to stdout or to a file).
___________________________ | handler 1 | | (formatter) | (treatment) | _______________ |---------------------------| | logger | ==> | -> string ==> ( * ) | |---------------| |___________________________| message ==> | -> log item | ___________________________ [_______________| ==> | handler 2 | | ... |
To each logger, handler and log message are associated a level, which will be used to filter the messages going through the logging infrastructure.
The predefined levels are, in increasing order of precedence :
By default, two handlers are provided:
Cli handler: outputs colored messages to stdout.
let h = Default_handlers.make (Cli Debug)
File handler : outputs messages to a given file.
let h = Default_handlers.make (File ("filename", Debug))
See more about default handlers at Easy_logging__Default_handlers
.
See complete class documentation at Easy_logging.Logging.logger
A logger object can be created directly :
let logger1 = new Logging.logger "my_logger1" (Some Warning) [Cli Debug]
or through the make_logger function :
let logger2 = Logging.make_logger "my_logger2" (Some Debug) [Cli Debug]
The make_logger
function will register the logger instance internaly so that it will be possible to access and modify it from anywhere in the program.
A logger object has two methods for each of the log levels.
logger1#debug "x is alive";
logger1#ldebug (lazy (heavy_calculation ()));