From e79e76b43bd5c20ad1306c4d564974557ab70e52 Mon Sep 17 00:00:00 2001 From: Maxime Levillain Date: Tue, 3 Dec 2024 11:40:12 +0100 Subject: [PATCH] add url log when debug is active --- src/request/ezCohttp_base.ml | 6 ++++-- src/request/js/fetch/ezFetch.ml | 4 +++- src/request/js/fetch/ezFetch_lwt.ml | 4 +++- src/request/js/nodejs/nodejs_common.ml | 4 +++- src/request/js/xhr/ezXhr.ml | 4 +++- src/request/js/xhr/ezXhr_lwt.ml | 4 +++- src/request/unix/curl/ezCurl_common.ml | 4 +++- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/request/ezCohttp_base.ml b/src/request/ezCohttp_base.ml index 3a302a8..2a4e3be 100644 --- a/src/request/ezCohttp_base.ml +++ b/src/request/ezCohttp_base.ml @@ -23,8 +23,10 @@ let meth_of_str = function | s -> `Other s let log ?(meth="GET") url = function - | None -> () - | Some msg -> Printf.printf "[>%s %s %s ]\n%!" msg meth url + | None -> + if !Verbose.v <> 0 then Format.printf "[ez_api] %s %s@." meth url + else () + | Some msg -> Format.printf "[>%s %s %s ]@." msg meth url module Make(Client:Cohttp_lwt.S.Client) = struct diff --git a/src/request/js/fetch/ezFetch.ml b/src/request/js/fetch/ezFetch.ml index ffdf95a..089dc80 100644 --- a/src/request/js/fetch/ezFetch.ml +++ b/src/request/js/fetch/ezFetch.ml @@ -12,7 +12,9 @@ open EzRequest open Ezjs_fetch let log ?(meth="GET") url = function - | None -> () + | None -> + if !Verbose.v <> 0 then Ezjs_min.log "[ez_api] %s %s@." meth url + else () | Some msg -> Ezjs_min.log_str ("[>" ^ msg ^ " " ^ meth ^ " " ^ url ^ "]") let handle_response ?msg url f r = diff --git a/src/request/js/fetch/ezFetch_lwt.ml b/src/request/js/fetch/ezFetch_lwt.ml index 1b3d628..b68d10e 100644 --- a/src/request/js/fetch/ezFetch_lwt.ml +++ b/src/request/js/fetch/ezFetch_lwt.ml @@ -14,7 +14,9 @@ open Ezjs_fetch_lwt let (>|=) = Lwt.(>|=) let log ?(meth="GET") ?msg url = match msg with - | None -> () + | None -> + if !Verbose.v <> 0 then Ezjs_min.log "[ez_api] %s %s@." meth url + else () | Some msg -> Ezjs_min.log_str ("[>" ^ msg ^ " " ^ meth ^ " " ^ url ^ "]") let handle_response ?msg url r = diff --git a/src/request/js/nodejs/nodejs_common.ml b/src/request/js/nodejs/nodejs_common.ml index c109f25..0cddeb0 100644 --- a/src/request/js/nodejs/nodejs_common.ml +++ b/src/request/js/nodejs/nodejs_common.ml @@ -44,7 +44,9 @@ class type http = object end let log ?(meth="GET") url = function - | None -> () + | None -> + if !Verbose.v <> 0 then log "[ez_api] %s %s@." meth url + else () | Some msg -> log_str ("[>" ^ msg ^ " " ^ meth ^ " " ^ url ^ "]") let require s = Unsafe.(fun_call (pure_js_expr "require") [|inject @@ string s|]) diff --git a/src/request/js/xhr/ezXhr.ml b/src/request/js/xhr/ezXhr.ml index 1935f13..c2de107 100644 --- a/src/request/js/xhr/ezXhr.ml +++ b/src/request/js/xhr/ezXhr.ml @@ -12,7 +12,9 @@ open Js_of_ocaml open Js let log ?(meth="GET") url = function - | None -> () + | None -> + if !Verbose.v <> 0 then Firebug.console##log (Js.string (Format.sprintf "[ez_api] %s %s@." meth url)) + else () | Some msg -> Firebug.console##log (string ("[>" ^ msg ^ " " ^ meth ^ " " ^ url ^ "]")) diff --git a/src/request/js/xhr/ezXhr_lwt.ml b/src/request/js/xhr/ezXhr_lwt.ml index 1d80eef..a7cbdb2 100644 --- a/src/request/js/xhr/ezXhr_lwt.ml +++ b/src/request/js/xhr/ezXhr_lwt.ml @@ -25,7 +25,9 @@ let meth_of_str ?(default=`GET) = function | _ -> default let log ?(meth="GET") ?msg url = match msg with - | None -> () + | None -> + if !Verbose.v <> 0 then Firebug.console##log (Js.string (Format.sprintf "[ez_api] %s %s@." meth url)) + else () | Some msg -> Firebug.console##log (Js.string ("[>" ^ msg ^ " " ^ meth ^ " " ^ url ^ "]")) let make ?msg ?content ?content_type ~meth ~headers url = diff --git a/src/request/unix/curl/ezCurl_common.ml b/src/request/unix/curl/ezCurl_common.ml index 03d0122..8a96877 100644 --- a/src/request/unix/curl/ezCurl_common.ml +++ b/src/request/unix/curl/ezCurl_common.ml @@ -12,7 +12,9 @@ let timeout = ref (Some 30) let set_timeout t = timeout := t let log ?(meth="GET") url = function - | None -> () + | None -> + if !Verbose.v <> 0 then Format.printf "[ez_api] %s %s@." meth url + else () | Some msg -> Format.printf "[>%s %s %s ]@." msg meth url let writer_callback a d =