package easy_logging

  1. Overview
  2. Docs
Module to log messages. Aimed at being both powerful and easy to use

Install

Dune Dependency

Authors

Maintainers

Sources

v0.5
md5=12fb8044e96ea1ace1cc465c766cde7e
sha512=17ab30169c54a13f3aff8605bd1acaffb911c6882fa3a0c7ad6c14b2dcbd3c08b0f2568fb0ec500ae6e741be926a49fb73954d2ccfedcd274463ffed20149b02

doc/easy_logging/Easy_logging/Handlers/index.html

Module Easy_logging.HandlersSource

Default implementation of a Handlers module.

This is the Handlers module. It provides simple yet adaptable handlers implementation.

Type definitions

Sourcetype tag = string
Sourcetype log_item = {
  1. level : Easy_logging__.Easy_logging_types.level;
  2. logger_name : string;
  3. msg : string;
  4. tags : string list;
}
Sourcetype log_formatter = log_item -> string
Sourcetype filter = log_item -> bool
Sourcetype t = {
  1. mutable fmt : log_formatter;
  2. mutable level : Easy_logging__.Easy_logging_types.level;
  3. mutable filters : filter list;
  4. output : out_channel;
}

type of a handler

A handler is made of:

  • a formatter that transforms a log item into a string.
  • a level used to filter out items.
  • an array of possible additional custom filters.
  • an out_channel, where log strings are outputed by the function Pervasives.output_string.

Formatting functions

Sourceval reduce : ('a -> 'a -> 'a) -> 'a list -> 'a -> 'a
Sourceval format_tags : string list -> string

Auxiliary functions.

Sourceval format_default : log_item -> string

Human readable log messages.

Sourceval format_color : log_item -> string

Human readable log messages, with level depending colors.

Sourceval format_json : log_item -> string

JSON logs for software interoperability.

Handlers creation helpers

Sourcetype file_handlers_config = {
  1. logs_folder : string;
  2. truncate : bool;
  3. file_perms : int;
}
Sourceval file_handlers_defaults : file_handlers_config
Sourcetype config = {
  1. mutable file_handlers : file_handlers_config;
}
Sourceval config : config
Sourceval set_config : config -> unit

Sets how log files are created when using make_file_handler

Sourceval make_cli_handler : Easy_logging__.Easy_logging_types.level -> t
Sourceval make_file_handler : Easy_logging__.Easy_logging_types.level -> string -> t
Sourcetype desc =
  1. | Cli of Easy_logging__.Easy_logging_types.level
  2. | File of string * Easy_logging__.Easy_logging_types.level
Sourceval make : desc -> t

Used for quick handler creation, e.g.

  • Cli handler: outputs colored messages to stdout

     let h = Handlers.make (Cli Debug) 
  • File handler : outputs messages to a given file

     let h = Handlers.make (File ("filename", Debug)) 

Handlers setup

Sourceval set_level : t -> Easy_logging__.Easy_logging_types.level -> unit

Sets the level of a handler.

Sourceval set_formatter : t -> log_formatter -> unit

Sets the formatter of a handler.

Sourceval add_filter : t -> filter -> unit

Adds a filter to a handler.

Sourceval apply : t -> log_item -> unit

Auxiliary function.

OCaml

Innovation. Community. Security.