Implement set-theoretic operation on 2WSATA (union, intersection,
[tatoo.git] / src / logger.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                               TAToo                                 *)
4 (*                                                                     *)
5 (*                     Kim Nguyen, LRI UMR8623                         *)
6 (*                   Université Paris-Sud & CNRS                       *)
7 (*                                                                     *)
8 (*  Copyright 2010-2013 Université Paris-Sud and Centre National de la *)
9 (*  Recherche Scientifique. All rights reserved.  This file is         *)
10 (*  distributed under the terms of the GNU Lesser General Public       *)
11 (*  License, with the special exception on linking described in file   *)
12 (*  ../LICENSE.                                                        *)
13 (*                                                                     *)
14 (***********************************************************************)
15
16 INCLUDE "utils.ml"
17 open Format
18
19 type level = [ `NORMAL (* regular output *)
20              | `STATS (* Statistics only given if -s *)
21              | `DEBUG] (* DEBUG STATEMENTS *)
22
23 let string_of_level = function
24 | `NORMAL -> "NORMAL"
25 | `STATS -> "STATS"
26 | `DEBUG -> "DEBUG"
27
28
29 let _o = ref err_formatter
30
31 let set_output o = _o := o
32
33 IFDEF DEBUG
34 THEN
35 let debug = true
36 ELSE
37 let debug = false
38 END
39
40 let kont fmt = fprintf fmt "@]@."
41
42 let msg level msg =
43   let do_ =
44     match level with
45       `NORMAL -> true
46     | `DEBUG when debug -> true
47     | `STATS when !Options.stats -> true
48     | _ -> false
49   in
50   if do_ then begin
51       fprintf !_o "@[%s: " (string_of_level level);
52       kfprintf kont !_o msg
53   end else
54       ifprintf !_o msg