diff --git a/CHANGES.md b/CHANGES.md index 52d79810b0..2579ef2814 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## current +- lwt_jsoo: Use logs for the warnings and document it (mseri #776) - lwt: Use logs to warn users about leaked bodies and document it (mseri #771) - lwt, lwt_unix: Improve use of logs and the documentation, fix bug in the Debug.enable_debug function (mseri #772) - lwt_jsoo: Fix exception on connection errors in chrome (mefyl #761) diff --git a/cohttp-lwt-jsoo.opam b/cohttp-lwt-jsoo.opam index faa760a1ef..24c7fbd200 100644 --- a/cohttp-lwt-jsoo.opam +++ b/cohttp-lwt-jsoo.opam @@ -26,6 +26,7 @@ depends: [ "dune" {>= "2.0"} "cohttp" {= version} "cohttp-lwt" {= version} + "logs" "lwt" {>= "3.0.0"} "lwt_ppx" {with-test} "conf-npm" {with-test} diff --git a/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml b/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml index 81a5172bfa..b6500d61a9 100644 --- a/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml +++ b/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml @@ -51,6 +51,10 @@ module IO = Cohttp_lwt__String_io module Header_io = Cohttp__Header_io.Make (IO) module Body_builder (P : Params) = struct + let src = Logs.Src.create "cohttp.lwt.jsoo" ~doc:"Cohttp Lwt JSOO module" + + module Log = (val Logs.src_log src : Logs.LOG) + (* perform the body transfer in chunks from string. *) let chunked_body_str text = let body_len = text##.length in @@ -109,16 +113,14 @@ module Body_builder (P : Params) = struct in match xhr_response_supported with | true when Js.Opt.return xml##.response == Js.null -> - Firebug.console##log - (Js.string "XHR Response is null; using empty string"); + Log.warn (fun m -> m "XHR Response is null; using empty string"); `String (Js.string "") | true -> Js.Opt.case (File.CoerceTo.arrayBuffer xml##.response) (fun () -> - Firebug.console##log - (Js.string - "XHR Response is not an arrayBuffer; using responseText"); + Log.warn (fun m -> + m "XHR Response is not an arrayBuffer; using responseText"); respText ()) (fun ab -> `ArrayBuffer ab) | false -> respText () diff --git a/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.mli b/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.mli index 71b6382c40..e1b330e7f1 100644 --- a/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.mli +++ b/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.mli @@ -15,7 +15,16 @@ * }}}*) -(** HTTP client for JavaScript using XMLHttpRequest. *) +(** {1 HTTP client for JavaScript using XMLHttpRequest.} + + The {!Logs} source name for this module's logger is ["cohttp.lwt.jsoo"]. To + log the current warnings using the browser's console log, you can write a + custom reporter or use: + + {[ + let reporter = Logs_browser.console_reporter () in + Logs.set_reporter reporter + ]} *) (** Configuration parameters for the XmlHttpRequest engines *) module type Params = sig diff --git a/cohttp-lwt-jsoo/src/dune b/cohttp-lwt-jsoo/src/dune index 9b1cc0a4a7..18a372c53a 100644 --- a/cohttp-lwt-jsoo/src/dune +++ b/cohttp-lwt-jsoo/src/dune @@ -4,4 +4,4 @@ (synopsis "XHR/Lwt based http client") (preprocess (pps js_of_ocaml-ppx)) - (libraries js_of_ocaml cohttp-lwt)) + (libraries js_of_ocaml cohttp-lwt logs))