Skip to content

Commit 0cdaae2

Browse files
committed
feat(Logger): debugging interface
1 parent d38ae1a commit 0cdaae2

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/Debugger.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
include DebuggerSigs
2+
3+
module Make () = struct
4+
type 'a Effect.t +=
5+
| Debug : Loctext.t -> unit Effect.t
6+
| CallBegin : Loctext.t -> unit Effect.t
7+
| CallEnd : Loctext.t -> unit Effect.t
8+
9+
let emit_loctext t = Effect.perform @@ Debug t
10+
let emit ?loc s = emit_loctext @@ Loctext.make ?loc s
11+
let emitf ?loc = Loctext.kmakef ?loc emit_loctext
12+
13+
let trace_open_loctext t = Effect.perform @@ CallBegin t
14+
let trace_close_loctext t = Effect.perform @@ CallEnd t
15+
16+
let trace ?loc s f =
17+
trace_open_loctext (Loctext.make ?loc s);
18+
Fun.protect f
19+
~finally:(fun () -> trace_close_loctext (Loctext.make ?loc s))
20+
let tracef ?loc =
21+
Text.kmakef @@ fun t f ->
22+
trace_open_loctext (Range.locate_opt loc t);
23+
Fun.protect f ~finally:(fun () -> trace_close_loctext (Range.locate_opt loc t))
24+
end

src/Debugger.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include module type of DebuggerSigs
2+
3+
module Make () : S

src/DebuggerSigs.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module type S =
2+
sig
3+
val emit : ?loc:Range.t -> string -> unit
4+
val emitf : ?loc:Range.t -> ('a, Format.formatter, unit, unit) format4 -> 'a
5+
val trace : ?loc:Range.t -> string -> (unit -> 'a) -> 'a
6+
val tracef : ?loc:Range.t -> ('b, Format.formatter, unit, (unit -> 'a) -> 'a) format4 -> 'b
7+
val run : emit:(Loctext.t -> unit) -> trace:([`Open | `Close] -> Loctext.t -> unit) -> (unit -> 'a) -> 'a
8+
end

0 commit comments

Comments
 (0)