package easy_logging

  1. Overview
  2. Docs

Default implementation of a Handlers module.

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

Type definitions

type tag = string
type log_item = {
  1. level : Easy_logging__.Easy_logging_types.level;
  2. logger_name : string;
  3. msg : string;
  4. tags : string list;
}
type log_formatter = log_item -> string
type filter = log_item -> bool
type 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

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

Auxiliary functions.

val format_default : log_item -> string

Human readable log messages.

val format_color : log_item -> string

Human readable log messages, with level depending colors.

val format_json : log_item -> string

JSON logs for software interoperability.

Handlers creation helpers

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

Sets how log files are created when using make_file_handler

val make_cli_handler : Easy_logging__.Easy_logging_types.level -> t
val make_file_handler : Easy_logging__.Easy_logging_types.level -> string -> t
type desc
val 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

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

Sets the level of a handler.

val set_formatter : t -> log_formatter -> unit

Sets the formatter of a handler.

val add_filter : t -> filter -> unit

Adds a filter to a handler.

val apply : t -> log_item -> unit

Auxiliary function.

OCaml

Innovation. Community. Security.