package simlog

  1. Overview
  2. Docs

Source file simlog.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Filter = Filter
module Formatter = Formatter
module Recorder = Recorder
module Printer = Printer

module type Logger = sig
  module Filter : Filter.T
  module Printer : Printer.T
  module Formatter : Formatter.T
  module Recorder : Recorder.T
end

module Builtin = struct
  module Logger : Logger = struct
    include Filter.Builtin
    include Formatter.Builtin
    include Recorder.Builtin
    module Printer = Printer.Builtin.Stdout_Mutex_Printer
  end
end

module Make (M : Logger) = struct
  let[@inline always] __record ~(level : Recorder.Level.t) ~(str : string) :
      unit =
    Recorder.record ~opt:M.Recorder.opt ~level str
    |> M.Filter.filter
    |> Option.iter (fun record ->
           M.Formatter.format record M.Printer.config.target |> M.Printer.print)

  let[@inline always] info (fmt : 'a) =
    Format.ksprintf (fun str -> __record ~str ~level:Recorder.Level.Info) fmt

  let[@inline always] error (fmt : 'a) =
    Format.ksprintf (fun str -> __record ~str ~level:Recorder.Level.Error) fmt

  let[@inline always] warn (fmt : 'a) =
    Format.ksprintf (fun str -> __record ~str ~level:Recorder.Level.Warn) fmt

  let[@inline always] debug (fmt : 'a) =
    Format.ksprintf (fun str -> __record ~str ~level:Recorder.Level.Debug) fmt
end