Module B0.Log

module Log: sig .. end
The B0 program log.

This log should be used to log general program activity not for logging build operations.

The module is modelled after Logs logging, see this quick introduction. It can be made to log on a Logs source, see here.

Reporting levels

type level = 
| Quiet
| App
| Error
| Warning
| Info
| Debug
The type for reporting levels.
val level : unit -> level
level () is the current reporting level.
val set_level : level -> unit
set_level l sets the current reporting level to l.
val pp_level : level B0.Fmt.t
pp_level ppf l prints and unspecified representation of l on ppf.
val level_to_string : level -> string
level_to_string l converts l to a string representation.
val level_of_string : string -> (level, [ `Msg of string ]) Pervasives.result
level_of_string s parses a level from s according to the representation of B0.Log.level_to_string.

Log functions

type ('a, 'b) msgf = (?header:string -> ('a, Format.formatter, unit, 'b) Pervasives.format4 -> 'a) ->
The type for client specified message formatting functions. See Logs.msgf.
type 'a log = ('a, unit) msgf -> unit 
The type for log functions. See Logs.log.
val msg : level -> 'a log
See Logs.msg.
val app : 'a log
app is msg App.
val err : 'a log
err is msg Error.
val warn : 'a log
warn is msg Warning.
val info : 'a log
info is msg Info.
val debug : 'a log
debug is msg Debug.
val kmsg : (unit -> 'b) -> level -> ('a, 'b) msgf -> 'b
kmsg k level m logs m with level level and continues with k.

Logging result value Errors

val on_error : ?level:level ->
?header:string ->
pp:'b B0.Fmt.t -> use:('b -> 'a) -> ('a, 'b) Pervasives.result -> 'a
See Logs.on_error.
val on_error_msg : ?level:level ->
?header:string ->
use:(unit -> 'a) -> ('a, [ `Msg of string ]) Pervasives.result -> 'a
See Logs.on_error_msg.

Logging timings

val time : ?level:level ->
('a -> (('b, Format.formatter, unit, 'a) Pervasives.format4 -> 'b) -> 'a) ->
('c -> 'a) -> 'c -> 'a
time ~level m f v logs m with level level (defaults to Info) and the time f v took as the log header.

Log monitoring

val err_count : unit -> int
err_count () is the number of messages logged with level Error.
val warn_count : unit -> int
warn_count () is the number of messages logged with level Warning.


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 set_kmsg : kmsg -> unit
set_kmsg kmsg sets the logging function to kmsg.