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
60 method enable = self#doCritical (lazy (enabled <- true))
61 method disable = self#doCritical (lazy (enabled <- false))
62 method log (prio: priority) msg =
63 self#doCritical (lazy (
64 if enabled && (int_of_priority prio <= level_no) then
65 prerr_endline (sprintf ("%s: %s") (string_of_priority prio) msg)
69 (** non thread safe, a processingLogger is usually instantied locally for each
71 class processingLogger =
72 let html_escape s = (* TODO too naive, use Nethtml.encode instead *)
73 Pcre.replace ~pat:"<" ~templ:"<"
74 (Pcre.replace ~pat:">" ~templ:">"
75 (Pcre.replace ~pat:"&" ~templ:"&" s))
79 val mutable log_lines: string list = []
80 method log msg = log_lines <- msg :: log_lines
81 method asText = String.concat "\n" (List.rev log_lines)
84 "<html><body>\n%s\n</body></html>"
87 (List.map html_escape (List.rev log_lines)))