Skip to content

Commit

Permalink
feat(Logger): debugging interface
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Nov 12, 2023
1 parent 6986a97 commit 47630ca
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Logger.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include LoggerSigs

type 'a Effect.t +=
| Debug : Diagnostic.loctext -> unit Effect.t
| CallBegin : Diagnostic.loctext -> unit Effect.t
| CallEnd : Diagnostic.loctext -> unit Effect.t

let debug_loctext t = Effect.perform @@ Debug t
let debug ?loc s = debug_loctext @@ Diagnostic.loctext ?loc s
let debugf ?loc = Diagnostic.kloctextf ?loc debug_loctext

let stalk_open_loctext t = Effect.perform @@ CallBegin t
let stalk_close_loctext t = Effect.perform @@ CallEnd t
let stalk ?loc s f =
stalk_open_loctext (Diagnostic.loctext ?loc s);
Fun.protect f
~finally:(fun () -> stalk_close_loctext (Diagnostic.loctext ?loc s))
let stalkf ?loc =
Diagnostic.ktextf @@ fun t f ->
stalk_open_loctext {Range.value = t; loc};
Fun.protect f
~finally:(fun () -> stalk_close_loctext {Range.value = t; loc})
3 changes: 3 additions & 0 deletions src/Logger.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include module type of LoggerSigs

module Make () : S
7 changes: 7 additions & 0 deletions src/LoggerSigs.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module type S =
sig
val debug : ?loc:Range.t -> string -> unit
val debugf : ?loc:Range.t -> ('a, Format.formatter, unit, unit) format4 -> 'a
val stalk : ?loc:Range.t -> string -> (unit -> 'a) -> 'a
val stalkf : ?loc:Range.t -> ('b, Format.formatter, unit, (unit -> 'a) -> 'a) format4 -> 'b
end

0 comments on commit 47630ca

Please sign in to comment.