X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Flogger.ml;fp=src%2Flogger.ml;h=aa9f6f5d03f0e16538ff9f8daad439bd9a11e2e2;hb=969febf12344a3fe3bf793a323b2e88f7b20ebae;hp=0000000000000000000000000000000000000000;hpb=acd23a33d837d03c813212ec3896a86edef16e87;p=tatoo.git diff --git a/src/logger.ml b/src/logger.ml new file mode 100644 index 0000000..aa9f6f5 --- /dev/null +++ b/src/logger.ml @@ -0,0 +1,54 @@ +(***********************************************************************) +(* *) +(* TAToo *) +(* *) +(* Kim Nguyen, LRI UMR8623 *) +(* Université Paris-Sud & CNRS *) +(* *) +(* Copyright 2010-2013 Université Paris-Sud and Centre National de la *) +(* Recherche Scientifique. All rights reserved. This file is *) +(* distributed under the terms of the GNU Lesser General Public *) +(* License, with the special exception on linking described in file *) +(* ../LICENSE. *) +(* *) +(***********************************************************************) + +INCLUDE "utils.ml" +open Format + +type level = [ `NORMAL (* regular output *) + | `STATS (* Statistics only given if -s *) + | `DEBUG] (* DEBUG STATEMENTS *) + +let string_of_level = function +| `NORMAL -> "NORMAL" +| `STATS -> "STATS" +| `DEBUG -> "DEBUG" + + +let _o = ref err_formatter + +let set_output o = _o := o + +IFDEF DEBUG +THEN +let debug = true +ELSE +let debug = false +END + +let kont fmt = fprintf fmt "@]@." + +let msg level msg = + let do_ = + match level with + `NORMAL -> true + | `DEBUG when debug -> true + | `STATS when !Options.stats -> true + | _ -> false + in + if do_ then begin + fprintf !_o "@[%s: " (string_of_level level); + kfprintf kont !_o msg + end else + ifprintf !_o msg