3 * Stefano Zacchiroli <zack@cs.unibo.it>
4 * for the HELM Team http://helm.cs.unibo.it/
6 * This file is part of HELM, an Hypertextual, Electronic
7 * Library of Mathematics, developed at the Computer Science
8 * Department, University of Bologna, Italy.
10 * HELM is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * HELM is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with HELM; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * For details, see the HELM World-Wide-Web page,
26 * http://helm.cs.unibo.it/
32 `Emerg | `Alert | `Crit | `Err | `Warning | `Notice | `Info | `Debug
35 let int_of_priority = function
45 let string_of_priority = function
46 | `Emerg -> "EMERGENCY"
50 | `Warning -> "WARNING"
55 class sysLogger ?(level: priority = `Notice) ?(outchan = stderr) () =
57 val level_no = int_of_priority level
58 val mutable enabled = false
60 method levelNo = level_no
61 method enable = enabled <- true
62 method disable = enabled <- false
63 method log (prio: priority) msg =
64 let tm = Unix.localtime (Unix.time ()) in
65 if enabled && (int_of_priority prio <= level_no) then begin
66 fprintf outchan ("[UWOBO %02d/%02d/%4d %02d:%02d:%02d] %s: %s\n")
67 tm.Unix.tm_mday (tm.Unix.tm_mon + 1) (tm.Unix.tm_year + 1900)
68 tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec
69 (string_of_priority prio) msg;
75 | Line of string (** normal line *)
76 | LineBold of string (** bold line *)
77 | LineEmph of string (** emph line *)
80 (** non thread safe, a processingLogger is usually instantied locally for each
82 class processingLogger =
83 let html_escape = Netencoding.Html.encode ~in_enc:`Enc_iso88591 () in
84 let html_of_line = function
85 | Line l -> html_escape l
86 | LineBold l -> "<b>" ^ html_escape l ^ "</b>"
87 | LineEmph l -> "<em>" ^ html_escape l ^ "</em>"
89 let text_of_line = function
96 val mutable log_lines = []
97 method log msg = log_lines <- Line msg :: log_lines
98 method logBold msg = log_lines <- LineBold msg :: log_lines
99 method logEmph msg = log_lines <- LineEmph msg :: log_lines
101 String.concat "\n" (List.rev (List.map text_of_line log_lines))
104 "<html><body>\n%s\n</body></html>"
105 (String.concat "<br />\n" (List.map html_of_line (List.rev log_lines)))