Skip to content

Commit e41fad9

Browse files
committed
feat(Logger): debugging interface
1 parent 563566f commit e41fad9

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/Logger.ml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include LoggerSigs
2+
3+
type 'a Effect.t +=
4+
| Debug : Diagnostic.loctext -> unit Effect.t
5+
| CallBegin : Diagnostic.loctext -> unit Effect.t
6+
| CallEnd : Diagnostic.loctext -> unit Effect.t
7+
8+
let debug_loctext t = Effect.perform @@ Debug t
9+
let debug ?loc s = debug_loctext @@ Diagnostic.loctext ?loc s
10+
let debugf ?loc = Diagnostic.kloctextf ?loc debug_loctext
11+
12+
let stalk_open_loctext t = Effect.perform @@ CallBegin t
13+
let stalk_close_loctext t = Effect.perform @@ CallEnd t
14+
let stalk ?loc s f =
15+
stalk_open_loctext (Diagnostic.loctext ?loc s);
16+
Fun.protect f
17+
~finally:(fun () -> stalk_close_loctext (Diagnostic.loctext ?loc s))
18+
let stalkf ?loc =
19+
Diagnostic.ktextf @@ fun t f ->
20+
stalk_open_loctext {Range.value = t; loc};
21+
Fun.protect f
22+
~finally:(fun () -> stalk_close_loctext {Range.value = t; loc})

src/Logger.mli

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include module type of LoggerSigs
2+
3+
module Make () : S

src/LoggerSigs.ml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module type S =
2+
sig
3+
val debug : ?loc:Range.t -> string -> unit
4+
val debugf : ?loc:Range.t -> ('a, Format.formatter, unit, unit) format4 -> 'a
5+
val stalk : ?loc:Range.t -> string -> (unit -> 'a) -> 'a
6+
val stalkf : ?loc:Range.t -> ('b, Format.formatter, unit, (unit -> 'a) -> 'a) format4 -> 'b
7+
end

0 commit comments

Comments
 (0)