Skip to content

Commit 2d17372

Browse files
authored
Merge pull request #682 from ocsigen/revert-670-lwt-logger
Revert "Remove lwt-logger"
2 parents b65eaa2 + 564fd9b commit 2d17372

File tree

6 files changed

+217
-2
lines changed

6 files changed

+217
-2
lines changed

META.js_of_ocaml.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ package "graphics" (
2424
requires = "js_of_ocaml-lwt.graphics"
2525
)
2626

27+
package "log" (
28+
requires = "js_of_ocaml-lwt.logger"
29+
)
30+
2731
package "ocamlbuild" (
2832
requires = "js_of_ocaml-ocamlbuild"
2933
)

doc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ MLIS+=$(wildcard ${SRC_DIR}ocamlbuild/*.mli)
1010
OTHER+=-I ${CMI_DIR}lib -package ocamlbuild -I ${CMI_DIR}ocamlbuild -I ../_build/install/default/lib/js_of_ocaml -I ../_build/install/default/lib/js_of_ocaml/deriving -I ../_build/install/default/lib/js_of_ocaml-tyxml
1111

1212
ifeq "${WITH_LWT}" "YES"
13-
OTHER += -package lwt -I ${CMI_DIR}lib/lwt
14-
MLIS+=$(wildcard ${SRC_DIR}lib/lwt/*.mli)
13+
OTHER += -package lwt -I ${CMI_DIR}lib/lwt -I ${CMI_DIR}lib/lwt/log
14+
MLIS+=$(wildcard ${SRC_DIR}lib/lwt/*.mli) $(wildcard ${SRC_DIR}lib/lwt/log/*.mli)
1515
ifeq "${WITH_GRAPHICS}" "YES"
1616
OTHER+=-package graphics -I ${CMI_DIR}lib/lwt/graphics
1717
MLIS+=$(wildcard ${SRC_DIR}lib/lwt/graphics/*.mli)

doc/api/index

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Lwt_js_events
3838
Lwt_js
3939
}
4040

41+
{2 Lwt logger - API Reference}
42+
43+
{!modules:
44+
Lwt_log_js
45+
}
46+
4147
{2 Graphics - API Reference}
4248

4349
{!modules:

lib/lwt/log/jbuild

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(jbuild_version 1)
2+
(library
3+
((name lwt_log_js)
4+
(public_name js_of_ocaml-lwt.logger)
5+
(synopsis "Lwt logger for js_of_ocaml.")
6+
(optional)
7+
(libraries (js_of_ocaml lwt lwt.log))
8+
(preprocess (pps (js_of_ocaml-ppx)))))

lib/lwt/log/lwt_log_js.ml

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

lib/lwt/log/lwt_log_js.mli

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
(* Js_of_ocaml library
2+
* http://www.ocsigen.org/js_of_ocaml/
3+
* Copyright (C) 2014 Hugo Heuzard
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, with linking exception;
8+
* either version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
*)
19+
20+
21+
include module type of Lwt_log_core
22+
with type level = Lwt_log_core.level
23+
and type logger = Lwt_log_core.logger
24+
and type section = Lwt_log_core.section
25+
and type template = Lwt_log_core.template
26+
and module Section = Lwt_log_core.Section
27+
28+
(** Lwt logger for js_of_ocaml *)
29+
30+
(** {2 Predefined logger} *)
31+
32+
val console : Lwt_log.logger
33+
(** Logger that use the javascript console object. *)
34+
35+
36+
(** {2 Logging functions} *)
37+
38+
val log : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> string -> unit Lwt.t
39+
(** [log ?section ?logger ~level message] logs a message.
40+
41+
[section] defaults to {!Section.main}. If [logger] is not
42+
specified, then the default one is used instead (see
43+
{!default}).
44+
45+
If [exn] is provided, then its string representation
46+
(= [Printexc.to_string exn]) will be append to the message, and if
47+
possible the backtrace will also be logged.
48+
49+
If [inspect] is provided, it will be append to the message.
50+
51+
[location] contains the location of the logging directive, it is
52+
of the form [(file_name, line, column)]. *)
53+
54+
val log_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> ('a, unit, string, unit Lwt.t) format4 -> 'a
55+
(** [log_f] is the same as [log] except that it takes a format
56+
string *)
57+
58+
val ign_log : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> string -> unit
59+
(** Same as {!log} but ignore the resulting thread. *)
60+
61+
val ign_log_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> level : level -> ('a, unit, string, unit) format4 -> 'a
62+
(** Same as {!log_f} but ignore the resulting thread. *)
63+
64+
(** The following functions are the same as {!log} except that their
65+
name determines which level is used.
66+
67+
For example {!info msg} is the same as {!log ~level:Info msg}.
68+
*)
69+
70+
val debug : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t
71+
val debug_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a
72+
val ign_debug : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit
73+
val ign_debug_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a
74+
75+
val info : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t
76+
val info_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a
77+
val ign_info : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit
78+
val ign_info_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a
79+
80+
val notice : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t
81+
val notice_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a
82+
val ign_notice : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit
83+
val ign_notice_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a
84+
85+
val warning : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t
86+
val warning_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a
87+
val ign_warning : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit
88+
val ign_warning_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a
89+
90+
val error : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t
91+
val error_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a
92+
val ign_error : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit
93+
val ign_error_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a
94+
95+
val fatal : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit Lwt.t
96+
val fatal_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit Lwt.t) format4 -> 'a
97+
val ign_fatal : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> string -> unit
98+
val ign_fatal_f : ?inspect : 'v -> ?exn : exn -> ?section : section -> ?location : (string * int * int) -> ?logger : logger -> ('a, unit, string, unit) format4 -> 'a

0 commit comments

Comments
 (0)