package mc2

  1. Overview
  2. Docs

Source file Log.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
(*
MSAT is free software, using the Apache license, see file LICENSE
Copyright 2014 Guillaume Bury
Copyright 2014 Simon Cruanes
*)

(** {1 Logging functions, real version} *)

let enabled = true (* NOTE: change here for 0-overhead *)

let debug_level_ = ref 0
let set_debug l = debug_level_ := l
let get_debug () = !debug_level_

let debug_fmt_ = ref Format.std_formatter

let set_debug_out f = debug_fmt_ := f

(* does the printing, inconditionally *)
let debug_real_ l k =
  k (fun fmt ->
    CCFormat.fprintf !debug_fmt_ "@[<2>@{<Blue>[%d|%.3f]@}@ "
      l (Sys.time());
    Format.kfprintf
      (fun fmt -> Format.fprintf fmt "@]@.")
      !debug_fmt_ fmt)

let[@inline] debugf l k =
  if enabled && l <= !debug_level_ then (
    debug_real_ l k;
  )

let[@inline] debug l msg = debugf l (fun k->k "%s" msg)
OCaml

Innovation. Community. Security.