]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/uwobo/src/ocaml/uwobo_logger.ml
- added support for default properties
[helm.git] / helm / uwobo / src / ocaml / uwobo_logger.ml
index 2907b0726df0058b15d828a720e51112d6e7c6ec..3a197041c220a39ba54992a4de800c314f82667b 100644 (file)
@@ -51,24 +51,27 @@ let string_of_priority = function
   | `Debug    -> "DEBUG"
 
 class sysLogger ?(level: priority = `Notice) () =
-  object
+  object (self)
+    inherit Uwobo_common.threadSafe
     initializer
       print_endline (sprintf "Logger started with level %s" (string_of_priority level))
     val level_no = int_of_priority level
     val mutable enabled = false
-    method enable = enabled <- true
-    method disable = enabled <- false
+    method level = level
+    method levelNo = level_no
+    method enable = self#doCritical (lazy (enabled <- true))
+    method disable = self#doCritical (lazy (enabled <- false))
     method log (prio: priority) msg =
-      if enabled && (int_of_priority prio <= level_no) then
-        prerr_endline (sprintf ("%s: %s") (string_of_priority prio) msg)
+      self#doCritical (lazy (
+        if enabled && (int_of_priority prio <= level_no) then
+          prerr_endline (sprintf ("[UWOBO] %s: %s") (string_of_priority prio) msg)
+      ))
   end
 
+  (** non thread safe, a processingLogger is usually instantied locally for each
+  thread *)
 class processingLogger =
-  let html_escape s = (* TODO too naive, use Nethtml.encode instead *)
-    Pcre.replace ~pat:"<" ~templ:"&lt;"
-      (Pcre.replace ~pat:">" ~templ:"&gt;"
-        (Pcre.replace ~pat:"&" ~templ:"&amp;" s))
-  in
+  let html_escape = Netencoding.Html.encode ~in_enc:`Enc_iso88591 () in
   fun () ->
   object
     val mutable log_lines: string list = []
@@ -77,8 +80,6 @@ class processingLogger =
     method asHtml =
       sprintf
         "<html><body>\n%s\n</body></html>"
-        (String.concat
-          "<br />\n"
-          (List.map html_escape (List.rev log_lines)))
+        (String.concat "<br />\n" (List.map html_escape (List.rev log_lines)))
   end