package pplumbing

  1. Overview
  2. Docs

Module LogSource

An interface to Logs using Pp_tty.

This module can be used in places where you'd use functions from Logs when you wish to build your formatted document with Pp_tty rather than with Format.

For example:

  let hello ?src () =
    Log.info ?src (fun () -> [ Pp.textf "Hello %s World!" "Friendly" ])
  ;;

Styles may be injected in the document using Pp_tty. For example:

  let hello ?src () =
    Log.info ?src (fun () ->
      [ Pp.concat
          ~sep:Pp.space
          [ Pp.text "Hello"
          ; Pp_tty.tag (Ansi_styles [ `Fg_blue ]) (Pp.verbatim "Colored")
          ; Pp.text "World!"
          ]
      ])
  ;;

Logs types aliases

Sourcetype level = Logs.level
Sourcetype src = Logs.src

Logging functions

Log interface

We've looked through sherlocode to get some sense of how the Logs interface is used. In the most common cases, the function m is applied directly without header nor tags. When the headers or tags are used, they are usually constant values for headers, and for tags, either a constant or a function from unit to tags, applied in the body of m.

Based on this remarks and on the fact that we don't need a format string anymore, we've proposed an interface where the m auxiliary function is removed.

We this interface, the previous example can be written as:

  let hello ?src ?header ?tags () =
    Log.info ?src ?header ?tags (fun () ->
      [ Pp.concat
          ~sep:Pp.space
          [ Pp.text "Hello"
          ; Pp_tty.tag (Ansi_styles [ `Fg_blue ]) (Pp.verbatim "Colored")
          ; Pp.text "World!"
          ]
      ])
  ;;
Sourcetype log = ?header:string -> ?tags:(unit -> Logs.Tag.set) -> (unit -> Pp_tty.t list) -> unit
Sourceval msg : ?src:src -> level -> log
Sourceval app : ?src:src -> log
Sourceval err : ?src:src -> log
Sourceval warn : ?src:src -> log
Sourceval info : ?src:src -> log
Sourceval debug : ?src:src -> log

Logs Interface

Sourcemodule Logs : sig ... end

Interface in the style of Logs.

OCaml

Innovation. Community. Security.