2 (* Copyright (C) 2002, HELM Team.
4 * This file is part of HELM, an Hypertextual, Electronic
5 * Library of Mathematics, developed at the Computer Science
6 * Department, University of Bologna, Italy.
8 * HELM is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * HELM is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with HELM; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * For details, see the HELM World-Wide-Web page,
24 * http://cs.unibo.it/helm/.
30 `Emerg | `Alert | `Crit | `Err | `Warning | `Notice | `Info | `Debug
33 let int_of_priority = function
43 let string_of_priority = function
44 | `Emerg -> "EMERGENCY"
48 | `Warning -> "WARNING"
53 class sysLogger ?(level: priority = `Notice) () =
55 inherit Uwobo_common.threadSafe
57 print_endline (sprintf "Logger started with level %s" (string_of_priority level))
58 val level_no = int_of_priority level
59 val mutable enabled = false
61 method levelNo = level_no
62 method enable = self#doCritical (lazy (enabled <- true))
63 method disable = self#doCritical (lazy (enabled <- false))
64 method log (prio: priority) msg =
65 self#doCritical (lazy (
66 if enabled && (int_of_priority prio <= level_no) then
67 prerr_endline (sprintf ("[UWOBO] %s: %s") (string_of_priority prio) msg)
71 (** non thread safe, a processingLogger is usually instantied locally for each
73 class processingLogger =
74 let html_escape = Netencoding.Html.encode ~in_enc:`Enc_iso88591 () in
77 val mutable log_lines: string list = []
78 method log msg = log_lines <- msg :: log_lines
79 method asText = String.concat "\n" (List.rev log_lines)
82 "<html><body>\n%s\n</body></html>"
83 (String.concat "<br />\n" (List.map html_escape (List.rev log_lines)))