module Lwt_log:Logging facilitysig..end
type level =
| |
Debug |
(* | Debugging message. They can be automatically removed byt hte 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 logger
Lwt provides loggers sending log messages to a file, syslog,
... but you can also create you own logger.
type 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 LWT_LOG environment
variable, which must contains one or more rules of the form
pattern -> level separated by ";". Where pattern is a string
that may contain *.
For example, if LWT_LOG contains:
access -> warning;
foo[*] -> error
then the level of the section "access" is Warning and the
level of any section matching "foo[*]" is Error.
If LWT_LOG is not defined then the rule "* -> notice" is
used instead.
val log : ?exn:exn ->
?section:section ->
?logger:logger -> level:level -> string -> unit Lwt.tlog ?section ?logger ~level message logs a message.
section defaults to Lwt_log.Section.main. If logger is not
specified, then the default one is used instead (see
Lwt_log.default).
If 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.
val log_f : ?exn:exn ->
?section:section ->
?logger:logger ->
level:level ->
('a, unit, string, unit Lwt.t) Pervasives.format4 -> 'alog_f is the same as log except that it takes a format
stringLwt_log.log except that their
name determines which level is used.
For example info msg is the same as log ~level:Info msg.
val debug : ?exn:exn ->
?section:section -> ?logger:logger -> string -> unit Lwt.tval debug_f : ?exn:exn ->
?section:section ->
?logger:logger ->
('a, unit, string, unit Lwt.t) Pervasives.format4 -> 'aval info : ?exn:exn ->
?section:section -> ?logger:logger -> string -> unit Lwt.tval info_f : ?exn:exn ->
?section:section ->
?logger:logger ->
('a, unit, string, unit Lwt.t) Pervasives.format4 -> 'aval notice : ?exn:exn ->
?section:section -> ?logger:logger -> string -> unit Lwt.tval notice_f : ?exn:exn ->
?section:section ->
?logger:logger ->
('a, unit, string, unit Lwt.t) Pervasives.format4 -> 'aval warning : ?exn:exn ->
?section:section -> ?logger:logger -> string -> unit Lwt.tval warning_f : ?exn:exn ->
?section:section ->
?logger:logger ->
('a, unit, string, unit Lwt.t) Pervasives.format4 -> 'aval error : ?exn:exn ->
?section:section -> ?logger:logger -> string -> unit Lwt.tval error_f : ?exn:exn ->
?section:section ->
?logger:logger ->
('a, unit, string, unit Lwt.t) Pervasives.format4 -> 'aval fatal : ?exn:exn ->
?section:section -> ?logger:logger -> string -> unit Lwt.tval fatal_f : ?exn:exn ->
?section:section ->
?logger:logger ->
('a, unit, string, unit Lwt.t) Pervasives.format4 -> 'amodule Section:sig..end
typetemplate =string
It is a string which may contains variables of the form
$(var), where var is one of:
date which will be replaced with the current datename which will be replaced by the program namepid which will be replaced by the pid of the programmessage which will be replaced by the message emitedlevel which will be replaced by a string representation of
the levelsection which will be replaced by the name of the
message's section"$(name): $(message)""$(date) $(name)[$(pid)]: $(message)"val render : buffer:Buffer.t ->
template:template ->
section:section -> level:level -> message:string -> unitrender ~buffer ~template ~section ~level ~message instantiate
all variables of template, and store the result in
buffer.exception Logger_closed
val make : output:(section -> level -> string list -> unit Lwt.t) ->
close:(unit -> unit Lwt.t) -> loggermake ~output ~close creates a new logger.output : is used to write logs. It is a function which
receive a section, a level and a list lines that must
be logged together.close : is used to close the loggerval close : logger -> unit Lwt.tval default : logger Pervasives.refval broadcast : logger list -> loggerbroadcast loggers is a logger which send messages to all the
given loggers.
Note: closing a broadcast logger does not close its
components.
val dispatch : (section -> level -> logger) -> loggerdispatch 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.dispatch
(fun section level ->
match Lwt_log.Section.name section, level with
| "access", _ -> access_logger
| _, Lwt_log.Error -> error_logger)
val null : loggertypesyslog_facility =[ `Auth
| `Authpriv
| `Console
| `Cron
| `Daemon
| `FTP
| `Kernel
| `LPR
| `Local0
| `Local1
| `Local2
| `Local3
| `Local4
| `Local5
| `Local6
| `Local7
| `NTP
| `News
| `Security
| `Syslog
| `UUCP
| `User ]
val syslog : ?template:template ->
?paths:string list ->
facility:syslog_facility -> unit -> loggersyslog ?template ?paths ~facility () creates an logger
which send message to the system logger.template : defaults to "$(date) $(name)[$(pid)]: $(section): $(message)"paths : is a list of path to try for the syslogd socket. It
default to ["/dev/log"; "/var/run/log"].val file : ?template:template ->
?mode:[ `Append | `Truncate ] ->
?perm:Unix.file_perm -> file_name:string -> unit -> loggerdesf_file ?template ?mode ?perm ~file_name () creates an
logger which will write messages to file_name.
mode = `Truncate then the file is truncated and previous
contents will be lost.mode = `Append, new messages will be appended at the end
of the filetemplate : defaults to "$(date): $(section): $(message)"mode : defaults to `Appendval channel : ?template:template ->
close_mode:[ `Close | `Keep ] ->
channel:Lwt_io.output_channel -> unit -> loggerchannel ?template ~close_mode ~channel () creates a logger
from a channel.
If close_mode = `Close then channel is closed when the
logger is closed, otherwise it is left open.
template : defaults to "$(name): $(section): $(message)"