B0_std.Log
Program 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.
type level =
| Quiet
Do not report anything.
*)| Stdout
Outputs 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.
| Stderr
Outputs 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.
| Error
For error conditions that prevent the program from running correctly.
*)| Warning
For suspicious conditions that do not prevent the program from running normally but may eventually lead to an error condition.
*)| Info
For conditions that allow the program user to get a better understanding of what the program is doing.
*)| Debug
For 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 -> unit
set_level l
sets the reporting level to l
.
val level_to_string : level -> string
level_to_string l
converts l
to a string representation.
val level_of_string : string -> (level, string) Stdlib.result
level_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) ->
'b
The 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 -> unit
The 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 ->
'a
if_error ~level ~use r
is:
v
, if r
is Ok v
use
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.result
val if_error_pp :
'b Fmt.t ->
?level:level ->
?header:string ->
use:'a ->
('a, 'b) Stdlib.result ->
'a
if_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.result
if_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) ->
'a
time ~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 cookbook.logging_main
val spawn_tracer : level -> Os.Cmd.spawn_tracer
spawn_tracer level
is a spawn tracer that logs with level level
. If level
is Log.level.Quiet
this is B0_std.Os.Cmd.spawn_tracer_nop
.
module Reporter : sig ... end
Reporting.