package gapi-ocaml

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

Basic logging facility

The purpose of this module is to define a mutable logging function which ensures to be always pointing to a valid logging implementation. By default, the function prints the messages to stderr, prepended by a timestamp. In Netplex context, the implementation is changed so that the Netplex logger is used instead (see Netplex_log), and the log and logf functions below have the same effect as the counterparts in Netplex_cenv with the same name.

type level = [
  1. | `Emerg
  2. | `Alert
  3. | `Crit
  4. | `Err
  5. | `Warning
  6. | `Notice
  7. | `Info
  8. | `Debug
]

The log levels (syslog-like)

type logger = level -> string -> unit

A logging function takes a level, and the message

val channel_logger : out_channel -> level -> logger

channel_logger ch lev: Prints all messages with a level of lev and higher to the channel ch. The output buffer is flushed after each message,

val current_logger : logger ref

The variable containing the current logger function. Defaults to channel_logger stderr `Debug at program startup. Assign something else to this variable in order to change the log destination or the log level.

Note that the function Netplex_main.run modifies current_logger so log messages are forwarded to the Netplex logger. It is then the Netplex framework that determines log destination and level.

val log : level -> string -> unit

Writes a log message

val logf : level -> ('a, unit, string, unit) format4 -> 'a

Writes a log message like printf

val level_weight : level -> int

A number correspondig to the level

val level_of_string : string -> level
val string_of_level : level -> string

Convert level names to strings and vice versa

val level_names : string array

The level names indexed by weight

type format = [
  1. | `Std
  2. | `ISO
]
val format_timestamp : format -> int -> (float * int) -> string

format_timestamp fmt digits (seconds,nanos): Formats the timestamp (seconds,nanos) and returns the string. Pass in digits the number of digits for fractional seconds.

  • `Std: This is the "%c" format of Netdate
  • `ISO: ISO-8601 format
val current_formatter : ((float * int) -> string) ref

The current timestamp formatter

Example: Change the format of timestamps to ISO with a precision of milliseconds:

Netlog.current_formatter := Netlog.format_timestamp `ISO 3
module Debug : sig ... end

Controlling messages for debugging Ocamlnet

OCaml

Innovation. Community. Security.