Easy logging

Logging library inspired by the Python logging module.

Easy_logging allows fine-grained tuning of of when and where and how log messages are printed, with relatively low configuration, and simple logger configuration and usage.

It has the following features :

Basic example
open Easy_logging
logger = Logging.make_logger "my_logger" (Some Debug) [Cli Debug]
logger#info "log_message" 

will output to the stdout a message of the form

1.306  my_logger    Info    log_message

Table of contents

  1. Overall description (see also Easy_logging)
  2. defaults

    1. Handlers (see also Easy_logging__Handlers)
    2. Loggers (see also Easy_logging.Logging.logger )
    3. The Logging module (see also Easy_logging.Logging)
  3. The MakeLogging functor (see also Easy_logging__Make_logging.MakeLogging )
  4. More examples
  5. Index of modules

Overall description

The logging infrastructure is based on four concepts:

loggers, handlers, log items and logging tree.

A call to logger will create a log item, which it will pass to its handlers. Each handler will treats the item (e.g. transform it to a string, and then outputs to stdout or to a file).

                                    | handler 1 |
               _______________      |-----------|
              |     logger    | ==> |   ( * )   |
              |---------------|     |___________|
(message) ==> | -> log item   |      ___________
              [_______________| ==> | handler 2 |
                                    |   ...     |

Logging tree

Loggers are stored in a tree structure, with the following properties :

                       A (Info, Cli Debug)
                     /    \
                  A.B      A.C
                 /            \
            A.B.D (Warning)    A.C.E (Debug, (File "f", Debug),

For example, with the above logging tree


To each logger and log message are associated a level, which will be used to filter the messages going through the logging infrastructure.

The predefined levels are, in increasing order of precedence :

  1. Debug : used for debugging.
  2. Trace : used between info and debug
  3. Info : used to trace program execution.
  4. Warning : used for warnings.
  5. Error : used for errors.
  6. Flash : used for one-shot debugging: displays an easy to spot message.
  7. NoLevel : used to filter out all messages.

Log items

A log item has type

type log_item = {
    level : level;          (* the level of the log item *)
    logger_name : string;   (* the name of the logger to which the log call was passed *)
    msg : string;           (* the actual log message *)
    tags : string list      (* a list of tags *)


Four handler creation helper function are provided. They instantiate handlers with a level of their own to filter messages :

Log file creation is governed by configuration values (setting up file name prefix/suffix, folder, file creation mode, etc...). The configuration can be specified when creating the handlers explicitely (like above), and a default configuration can be set in the Logging module.

See more at Easy_logging.Handlers


See complete class documentation at Easy_logging.Logging.logger


A logger object can be created directly (in which case it will not be part of the logging tree)

let logger1 = new Logging.logger "my_logger1" 

or through helper functions of the The Logging module module.


A logger object has three methods for each of the log levels:

The Logging module

The Easy_logging.Logging module is the application of MakeLogging over Handlers. It provides two functions :

The MakeLogging functor

The MakeLogging functor takes a Easy_logging__.Easy_logging_types.HandlersT typed module, and creates a Logging module.


When declaring your Handlers module, do not coerce it the type HandlersT, because then its internal types t and desc won't be accessible.


See the examples page for more examples.

Index of modules

  1. Easy_logging__Colorize
  2. Easy_logging
  3. Easy_logging__Formatters
  4. Easy_logging__Handlers
  5. Easy_logging__Logging_infra
  6. Easy_logging__Logging_types
  7. Easy_logging__Make_logging