X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fhttp_getter%2Fhttp_getter_debugger.ml;h=3f9afd78c1e93ba5dbf2b50e4c431a13e1e70ac3;hb=d3c72d6856cd185e5b3e9f2e8b928b78c7031ed1;hp=57b8442ae96eb2834ea8eb44f2c204a52e8c19e2;hpb=5b6bfdb5e3e9641c2697258d65db154868c0ce79;p=helm.git diff --git a/helm/http_getter/http_getter_debugger.ml b/helm/http_getter/http_getter_debugger.ml index 57b8442ae..3f9afd78c 100644 --- a/helm/http_getter/http_getter_debugger.ml +++ b/helm/http_getter/http_getter_debugger.ml @@ -1,5 +1,7 @@ (* - * Copyright (C) 2003, HELM Team. + * Copyright (C) 2003-2004: + * Stefano Zacchiroli + * for the HELM Team http://helm.cs.unibo.it/ * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science @@ -21,10 +23,36 @@ * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, - * http://cs.unibo.it/helm/. + * http://helm.cs.unibo.it/ *) - (* debugging settings *) -let debug = true;; -let debug_print s = if debug then prerr_endline ("[HTTP-Getter] " ^ s);; +let debug = ref true + +(* invariant: if logfile is set, then logchan is set too *) +let logfile = ref None +let logchan = ref None + +let set_logfile f = + (match !logchan with None -> () | Some oc -> close_out oc); + match f with + | Some f -> + logfile := Some f; + logchan := Some (open_out f) + | None -> + logfile := None; + logchan := None + +let get_logfile () = !logfile + +let close_logfile () = set_logfile None + +let debug_print s = + let msg = "[HTTP-Getter] " ^ s in + if !debug then + match (!logfile, !logchan) with + | None, _ -> prerr_endline msg + | Some fname, Some oc -> + output_string oc msg; + flush oc + | Some _, None -> assert false