Module B0_std.Log
Program log.
Support for program logging. Not to be used by build logic.
The module is modelled after Logs logging, see this quick introduction. It can be made to log on a Logs source, see here.
FIXME This should maybe moved to B0_ui. Make the doc self contained (cf. references to Logs).
Reporting levels
type level=|Quiet|App|Error|Warning|Info|DebugThe type for reporting levels. They are meant to be used as follows:
Quietdoesn't report anything.Appcan be used for the standard output or console of an application. Using this instead ofstdoutdirectly allows the output to be silenced byQuietwhich may be desirable, or not.Erroris an error condition that prevents the program from running.Warningis a suspicious condition that does not prevent the program from running normally but may eventually lead to an error condition.Infois a condition that allows the program user to get a better understanding of what the program is doing.Debugis a condition that allows the program developer to get a better understanding of what the program is doing.
val level : unit -> levellevel ()is the current reporting level.
val set_level : level -> unitset_level lsets the current reporting level tol.
val level_to_string : level -> stringlevel_to_string lconvertslto a string representation.
val level_of_string : string -> (level, string) Stdlib.Pervasives.resultlevel_of_string sparses a level fromsaccording to the representation oflevel_to_string.
Log functions
type ('a, 'b) msgf= (?header:string -> ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'a) -> 'bThe type for client specified message formatting functions. See
Logs.msgf.
type 'a log= ('a, unit) msgf -> unitThe type for log functions. See
Logs.log.
val quiet : 'a logquietismsg Quiet.
val app : 'a logappismsg App.
val err : 'a logerrismsg Error.
val warn : 'a logwarnismsg Warning.
val info : 'a loginfoismsg Info.
val debug : 'a logdebugismsg Debug.
val kmsg : (unit -> 'b) -> level -> ('a, 'b) msgf -> 'bkmsg k level mlogsmwith levelleveland continues withk.
Logging result value Error messages
val if_error : ?level:level -> ?header:string -> use:'a -> ('a, string) Stdlib.Pervasives.result -> 'aif_error ~level ~use v ris:v, ifrisOk vuseandeis logged withlevel(defaults toError), ifrisError e.
val warn_if_error : ?header:string -> use:'a -> ('a, string) Stdlib.Pervasives.result -> 'awarn_if_errorisif_error ~level:Warning.
val if_error_pp : ?level:level -> ?header:string -> 'b Fmt.t -> use:'a -> ('a, 'b) Stdlib.Pervasives.result -> 'aif_error_pp ~level pp ~use risv, ifrisOk v.useandeis logged withlevel(defaults toError) usingpp, ifrisError e.
Logging timings
val time : ?level:level -> ('a -> (('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'b) -> 'a) -> (unit -> 'a) -> 'atime ~level m flogsmwith levellevel(defaults toInfo) and the timef ()took as the log header.
Log monitoring
Logger
The following function allows to change the logging backend. Note that in this case monitoring and level functions are no longer relevant.
type kmsg={kmsg : a b. (unit -> 'b) -> level -> ('a, 'b) msgf -> 'b;}The type for the basic logging function. The function is never invoked with a level of
Quiet.
val kmsg_nop : kmsgnop_kmsgis a logger that does nothing.
val kmsg_default : kmsgkmsg_defaultis the default logger that logs messages onFmt.stderrexcept forLog.level.Applevel which logs onFmt.stdout.
val set_kmsg : kmsg -> unitset_kmsg kmsgsets the logging function tokmsg.