package topkg

  1. Overview
  2. Docs

Topkg log.

Reporting levels

type level =
  1. | App
  2. | Error
  3. | Warning
  4. | Info
  5. | Debug

The type for reporting levels.

val level : unit -> level option

level () is the current reporting level.

val set_level : level option -> unit

set_level l sets the current reporting level to l.

val level_to_string : level option -> string

level_to_string l converts l to an unspecified human-readable US-ASCII string that can be parsed back by level_of_string.

val level_of_string : string -> (level option, [ `Msg of string ]) r

level_of_string s parses the representation of level_to_string from s.

Log functions

type 'a msgf = (?header:string -> ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'a) -> unit
val msg : level -> 'a msgf -> unit

msg l (fun m -> m fmt ...) logs with level l a message formatted with fmt.

val app : 'a msgf -> unit

app is msg App.

val err : 'a msgf -> unit

err is msg Error.

val warn : 'a msgf -> unit

err is msg Warning.

val info : 'a msgf -> unit

err is msg Info.

val debug : 'a msgf -> unit

err is msg Debug.

val on_error_msg : ?level:level -> use:(unit -> 'a) -> 'a result -> 'a

on_error_msg ~level r is:

  • v if r = Ok v
  • use e if r = Error (`Msg e). As a side effect e is logged with level level (defaults to Error).

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.

OCaml

Innovation. Community. Security.