Skip to content

Commit

Permalink
add url log when debug is active
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Dec 3, 2024
1 parent db0d5df commit e79e76b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/request/ezCohttp_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/request/js/fetch/ezFetch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 3 additions & 1 deletion src/request/js/fetch/ezFetch_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 3 additions & 1 deletion src/request/js/nodejs/nodejs_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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|])
Expand Down
4 changes: 3 additions & 1 deletion src/request/js/xhr/ezXhr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ^ "]"))

Expand Down
4 changes: 3 additions & 1 deletion src/request/js/xhr/ezXhr_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 3 additions & 1 deletion src/request/unix/curl/ezCurl_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit e79e76b

Please sign in to comment.