1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
(* Js_of_ocaml library
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2014 Hugo Heuzard
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
include Lwt_log_core
open Js_of_ocaml
open! Import
let js_val = Lwt.new_key ()
let console =
make
~close:(fun _ -> Lwt.return_unit)
~output:(fun section level logs ->
let str =
Js.string
(Printf.sprintf "[%s] %s" (Section.name section) (String.concat "\n" logs))
in
(match level, Lwt.get js_val with
| Debug, None -> Firebug.console##debug str
| Debug, Some v -> Firebug.console##debug_2 str v
| Info, None | Notice, None -> Firebug.console##info str
| Info, Some v | Notice, Some v -> Firebug.console##info_2 str v
| Warning, None -> Firebug.console##warn str
| Warning, Some v -> Firebug.console##warn_2 str v
| Error, None | Fatal, None -> Firebug.console##error str
| Error, Some v | Fatal, Some v -> Firebug.console##error_2 str v);
Lwt.return_unit)
let log ?inspect ?exn ?section ?location ?logger ~level message =
let inspect =
match inspect with
| None -> None
| Some v -> Some (Obj.repr v)
in
Lwt.with_value js_val inspect (fun () ->
log ?exn ?section ?location ?logger ~level message)
let log_f ?inspect ?exn ?section ?location ?logger ~level format =
Printf.ksprintf (log ?inspect ?exn ?section ?location ?logger ~level) format
let ign_log ?inspect ?exn ?section ?location ?logger ~level message =
try ignore (log ?inspect ?exn ?section ?location ?logger ~level message) with _ -> ()
let ign_log_f ?inspect ?exn ?section ?location ?logger ~level format =
Printf.ksprintf (ign_log ?inspect ?exn ?section ?location ?logger ~level) format
let debug ?inspect ?exn ?section ?location ?logger msg =
log ?inspect ?exn ?section ?location ?logger ~level:Debug msg
let debug_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (debug ?inspect ?exn ?section ?location ?logger) fmt
let info ?inspect ?exn ?section ?location ?logger msg =
log ?inspect ?exn ?section ?location ?logger ~level:Info msg
let info_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (info ?inspect ?exn ?section ?location ?logger) fmt
let notice ?inspect ?exn ?section ?location ?logger msg =
log ?inspect ?exn ?section ?location ?logger ~level:Notice msg
let notice_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (notice ?inspect ?exn ?section ?location ?logger) fmt
let warning ?inspect ?exn ?section ?location ?logger msg =
log ?inspect ?exn ?section ?location ?logger ~level:Warning msg
let warning_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (warning ?inspect ?exn ?section ?location ?logger) fmt
let error ?inspect ?exn ?section ?location ?logger msg =
log ?inspect ?exn ?section ?location ?logger ~level:Error msg
let error_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (error ?inspect ?exn ?section ?location ?logger) fmt
let fatal ?inspect ?exn ?section ?location ?logger msg =
log ?inspect ?exn ?section ?location ?logger ~level:Fatal msg
let fatal_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (fatal ?inspect ?exn ?section ?location ?logger) fmt
let ign_debug ?inspect ?exn ?section ?location ?logger msg =
ign_log ?inspect ?exn ?section ?location ?logger ~level:Debug msg
let ign_debug_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (ign_debug ?inspect ?exn ?section ?location ?logger) fmt
let ign_info ?inspect ?exn ?section ?location ?logger msg =
ign_log ?inspect ?exn ?section ?location ?logger ~level:Info msg
let ign_info_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (ign_info ?inspect ?exn ?section ?location ?logger) fmt
let ign_notice ?inspect ?exn ?section ?location ?logger msg =
ign_log ?inspect ?exn ?section ?location ?logger ~level:Notice msg
let ign_notice_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (ign_notice ?inspect ?exn ?section ?location ?logger) fmt
let ign_warning ?inspect ?exn ?section ?location ?logger msg =
ign_log ?inspect ?exn ?section ?location ?logger ~level:Warning msg
let ign_warning_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (ign_warning ?inspect ?exn ?section ?location ?logger) fmt
let ign_error ?inspect ?exn ?section ?location ?logger msg =
ign_log ?inspect ?exn ?section ?location ?logger ~level:Error msg
let ign_error_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (ign_error ?inspect ?exn ?section ?location ?logger) fmt
let ign_fatal ?inspect ?exn ?section ?location ?logger msg =
ign_log ?inspect ?exn ?section ?location ?logger ~level:Fatal msg
let ign_fatal_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (ign_fatal ?inspect ?exn ?section ?location ?logger) fmt
(*let raise_error ?inspect ?exn ?section ?location ?logger msg =
Lwt.ignore_result (log ?inspect ?exn ?section ?location ?logger ~level:Error msg);
failwith msg *)
(*let raise_error_f ?inspect ?exn ?section ?location ?logger fmt =
Printf.ksprintf (raise_error ?inspect ?exn ?section ?location ?logger) fmt *)
|