package batteries

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Simple logging

  • author Edgar Friendly
val output : unit BatIO.output ref

This ref holds the output channel for simple logging. Defaults to stderr

  • since 2.0; had getter and setter in 1.x
val prefix : string ref

This ref holds the text printed before each log message. Defaults to the empty string.

  • since 2.0; had getter and setter in 1.x
type flag = [
  1. | `Date
    (*

    Print the current date as 2011-06-28

    *)
  2. | `Time
    (*

    Print the current time as 01:23:45

    *)
  3. | `Filepos
    (*

    Print the file and linenum of this log command (UNIMPLEMENTED - needs syntax extension)

    *)
  4. | `Custom of unit -> string
    (*

    Print the results of running the given closure

    *)
]
val flags : flag list ref

This ref holds the output flags. These flags control how the log messages are output. The default is `Date; `Time and log messages are printed as:

2011/0628 01:23:45: prefixmessage

  • since 2.0; had getter and setter in 1.x
val log : ?fp:string -> string -> unit

log s logs the message s, returning unit.

  • since 2.0; was [print] in 1.x
val logf : ?fp:string -> ('a, unit BatIO.output, unit) format -> 'a

As Printf.printf, only the message is printed to the logging output and prefixed with status information per the current flags and the currently set prefix.

  • since 2.0; was [printf] in 1.x
val fatal : ?fp:string -> string -> 'a

fatal s logs the message s and then calls exit 1. This exits the program with return code 1.

val fatalf : ?fp:string -> ('a, unit BatIO.output, unit) format -> 'a

fatalf allows a format string (as Printf.printf)and the arguments to that format string to build the logging message. Exits the program with return code 1.

module type Config = sig ... end
module Make (S : Config) : sig ... end

Build a logger module with custom, fixed output, prefix and flags

Returns an object with methods fatal, fatalf, log, and logf that logs to the given output channel, with given prefix and flags. These methods work like the corresponding functions in the BatLog module.

  • since 2.0
val make_logger : 'a BatIO.output -> string -> [< `Custom of unit -> string | `Date | `Filepos | `Time ] list -> < fatal : ?fp:string -> string -> 'b ; fatalf : ?fp:string -> ('c, 'a BatIO.output, unit, unit, unit, 'd) format6 -> 'c ; log : ?fp:string -> string -> unit ; logf : ?fp:string -> ('e, 'a BatIO.output, unit) format -> 'e >
type easy_lev = [
  1. | `trace
  2. | `debug
  3. | `info
  4. | `warn
  5. | `error
  6. | `fatal
  7. | `always
]

The different verbosity levels supported in the Easy logger

module Easy : sig ... end

A simple-to-use logger with verbosity levels that outputs by default to stderr (changeable at runtime) with the date and time at the beginning of each log message.

module type Level_sig = sig ... end

The details of a level scheme for verbosity-level loggers

module Make_lev (L : Level_sig) (S : Config) : sig ... end

Make your own level-based logger, like Easy

OCaml

Innovation. Community. Security.