end
end
+type lineType =
+ | Line of string (** normal line *)
+ | LineBold of string (** bold line *)
+ | LineEmph of string (** emph line *)
+;;
+
(** non thread safe, a processingLogger is usually instantied locally for each
thread *)
class processingLogger =
let html_escape = Netencoding.Html.encode ~in_enc:`Enc_iso88591 () in
+ let html_of_line = function
+ | Line l -> html_escape l
+ | LineBold l -> "<b>" ^ html_escape l ^ "</b>"
+ | LineEmph l -> "<em>" ^ html_escape l ^ "</em>"
+ in
+ let text_of_line = function
+ | Line l -> l
+ | LineBold l -> l
+ | LineEmph l -> l
+ in
fun () ->
object
- val mutable log_lines: string list = []
- method log msg = log_lines <- msg :: log_lines
- method asText = String.concat "\n" (List.rev log_lines)
+ val mutable log_lines = []
+ method log msg = log_lines <- Line msg :: log_lines
+ method logBold msg = log_lines <- LineBold msg :: log_lines
+ method logEmph msg = log_lines <- LineEmph msg :: log_lines
+ method asText =
+ String.concat "\n" (List.rev (List.map text_of_line log_lines))
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_of_line (List.rev log_lines)))
end