B0_std.LogProgram log.
Examples:
let () = Log.warn (fun m -> m "The queue is full (%d elements)" count)
let () = Log.err (fun m -> m "The request timed out after %a" Mtime.pp dur)
let items =
Log.time (fun v m -> m "Purged, %d items remaining" (List.length v)) @@
(fun () -> purge items)See also the cookbook on logging.
TODO. Think about implicit locations.
type level = | QuietDo not report anything.
*)| StdoutOutputs to the stdout of the program. Using this allows the output to be silenced when the level is set to Quiet, which may be desirable, or not.
| StderrOutputs to the stderr of the program. Using this allows the output to be silenced when the level is set to Quiet, which may be desirable, or not.
| ErrorFor error conditions that prevent the program from running correctly.
*)| WarningFor suspicious conditions that do not prevent the program from running normally but may eventually lead to an error condition.
*)| InfoFor conditions that allow the program user to get a better understanding of what the program is doing.
*)| DebugFor conditions that allow the program developer to get a better understanding of what the program is doing.
*)The type for reporting levels.
val set_level : level -> unitset_level l sets the reporting level to l.
Use B0_std_cli.set_log_level to set this from the command line.
val level_to_string : level -> stringlevel_to_string l converts l to a string representation.
val level_of_string : string -> (level, string) Stdlib.resultlevel_of_string s parses a level from s according to the representation of level_to_string.
type ('a, 'b) msgf =
(?header:string ->
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'a) ->
'bThe type for client specified message formatting functions.
A message formatting function is called with a message construction function m. The message formatting function must call the given message construction function with an optional header, a format string and its arguments to define the message contents. Here are a few examples of message formatting functions:
(fun m -> m "%d messages to send" n)
(fun m -> m ~header:"emails" "%d messages to send" n)The interpretation of the optional header argument of m is up to the reporter but None should automatically output a header that depend on the log level and Some "" should not output any header, leaving full control of the log formatting to the client.
type 'a log = ('a, unit) msgf -> unitThe type for log functions.
msg level (fun m -> m fmt …) logs with level level a message formatted with fmt. For the semantics of levels see level.
kmsg k level (fun m -> m fmt …) logs with level level a message formatted with fmt and continues with k.
result errorsval if_error :
?level:level ->
?header:string ->
use:'a ->
('a, string) Stdlib.result ->
'aif_error ~level ~use r is:
v, if r is Ok vuse and e is logged using Fmt.lines with level (defaults to Error), if r is Error e.val if_error' :
?level:level ->
?header:string ->
use:'a ->
('a, string) Stdlib.result ->
('a, 'b) Stdlib.resultval if_error_pp :
'b Fmt.t ->
?level:level ->
?header:string ->
use:'a ->
('a, 'b) Stdlib.result ->
'aif_error_pp ~level pp ~use r is
v, if r is Ok v.use and e is logged with level (defaults to Error) using pp, if r is Error e.val if_error_pp' :
'b Fmt.t ->
?level:level ->
?header:string ->
use:'a ->
('a, 'b) Stdlib.result ->
('a, 'b) Stdlib.resultif_error_pp' is if_error_pp' wrapped by Result.ok
val time :
?level:level ->
('a -> (('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'b) -> 'a) ->
(unit -> 'a) ->
'atime ~level m f logs m with level level (defaults to Info) and the time f () took as the message header with Mtime.Span.pp.
Note. The reporting level is determined after f has been called. This means f can change it to affect the report. See for example How do I log the time taken by my program ?
value pp v reports v on level (defaults to Stderr) with pp if id is specified this is of the form "%s: %a" and returns v
module Reporter : sig ... endReporting.