open Format type t = string type level = int let loggers = [ "top-down-run"; "top-down-approx"; "result-set"; "level2-jit"; "res-jit"; "grammar"; "twopass";"transition" ] let active_loggers : (t, int) Hashtbl.t = Hashtbl.create 17 let available () = loggers let is_logger s = List.mem s loggers let level s = try Hashtbl.find active_loggers s with Not_found -> 0 let is_active s = Hashtbl.mem active_loggers s let activate s lvl = if not (is_active s) then Hashtbl.add active_loggers s lvl let deactivate s = Hashtbl.remove active_loggers s let logger_output = ref err_formatter let set_output f = logger_output := f let log t l s = if l <= level t then begin fprintf !logger_output "%s: " t; fprintf !logger_output "%s%!" s end