This module provides functions to deal with logging. It support:
# | Debug
|(*||Debugging message. They can be automatically removed by the syntax extension.||*)|
# | Info
|(*||Informational message. Suitable to be displayed when the program is in verbose mode.||*)|
# | Notice
|(*||Same as Info, but is displayed by default.||*)|
# | Warning
|(*||Something strange happend||*)|
# | Error
|(*||An error message, which should not means the end of the program.||*)|
# | Fatal
|(*||A fatal error happened, in most cases the program will end after a fatal error.||*)|
Type of log levels. A level determines the importance of a message
Type of a logger. A logger is responsible for dispatching messages and storing them somewhere.
Each logging message has a section. Sections can be used to structure your logs. For example you can choose different loggers according to the section.
Each section carries a level, and messages with a lower log level than than the section level will be dropped.
Section levels are initialised using the contents of the
environment variable, which must contain one or more rules of the form
pattern -> level separated by ";". Where
pattern is a string
that may contain
For example, if
access -> warning; foo[*] -> error
If the pattern is omited in a rule then the pattern
used instead, so
LWT_LOG may just contains
By default, the following rule apply :
"* -> notice"
Reset the rules set when parsing the
LWT_LOG environment variable using this
add_rule pattern level adds a rule for sections logging
levels. The rule is added before all other rules. It takes
effect immediately and affect all sections for which the level
has not been set explicitly with Section.set_level.
*. For example:
Lwt_log_core.add_rule "lwt*" Lwt_log_core.Info
append_rule pattern level adds the given rule after all other
rules. For example to set the default fallback rule:
Lwt_log_core.append_rule "*" Lwt_log_core.Info
log ?section ?logger ~level message logs a message.
exn is provided, then its string representation
Printexc.to_string exn) will be append to the message, and if
possible the backtrace will also be logged.
location contains the location of the logging directive, it is
of the form
(file_name, line, column).
The following functions are the same as log except that their name determines which level is used.
For example [root:info msg] is the same as [root:log ~level:Info msg].
A template is for generating log messages.
It is a string which may contains variables of the form
var is one of:
messagewhich will be replaced by the message emited
levelwhich will be replaced by a string representation of the level
sectionwhich will be replaced by the name of the message's section
loc-filewhich will be replaced by the file name of the calling logging function
loc-linewhich will be replaced by the line number of the calling logging function
loc-columnwhich will be replaced by the column number of the calling logging function
"$(name): $(loc-file): $(loc-line): $(loc-column): $(message)"
Exception raised when trying to use a closed logger
make ~output ~close creates a new logger.
dispatch f is a logger which dispatch logging instructions to
different logger according to their level and/or section.
Here is an example:
let access_logger = Lwt_log.file "access.log" and error_logger = Lwt_log.file "error.log" in Lwt_log_core.dispatch (fun section level -> match Lwt_log_core.Section.name section, level with | "access", _ -> access_logger | _, Lwt_log_core.Error -> error_logger)