trace-tef: additional argument to with_setup; env for "stdout"/"stderr"

This commit is contained in:
Simon Cruanes 2023-06-12 13:30:06 -04:00
parent ee2e5dd651
commit 088f2a5e7f
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 14 additions and 7 deletions

View file

@ -316,12 +316,14 @@ let setup ?(out = `Env) () =
let path = "trace.json" in
let c = collector ~out:(`File path) () in
Trace.setup_collector c
| Some "stdout" -> Trace.setup_collector @@ collector ~out:`Stdout ()
| Some "stderr" -> Trace.setup_collector @@ collector ~out:`Stderr ()
| Some path ->
let c = collector ~out:(`File path) () in
Trace.setup_collector c
| None -> ())
let with_setup ?out f =
let with_setup ?out () f =
setup ?out ();
protect ~finally:Trace.shutdown f

View file

@ -24,13 +24,18 @@ val setup : ?out:[ output | `Env ] -> unit -> unit
- [`Env] will enable tracing if the environment
variable "TRACE" is set.
If it's set to anything but "1", the value is taken
to be the file path into which to write.
If it's set to "1", then the file is "trace.json".
- If it's set to "1", then the file is "trace.json".
- If it's set to "stdout", then logging happens on stdout (since 0.2)
- If it's set to "stderr", then logging happens on stdout (since 0.2)
- Otherwise, if it's set to a non empty string, the value is taken
to be the file path into which to write.
*)
val with_setup : ?out:[ output | `Env ] -> (unit -> 'a) -> 'a
(** Setup, and make sure to shutdown before exiting *)
val with_setup : ?out:[ output | `Env ] -> unit -> (unit -> 'a) -> 'a
(** [with_setup () f] (optionally) sets a collector up, calls [f()],
and makes sure to shutdown before exiting.
since 0.2 a () argument was added.
*)
(**/**)

View file

@ -17,4 +17,4 @@ let run () =
let () =
Trace_tef.Internal_.mock_all_ ();
Trace_tef.with_setup ~out:`Stdout @@ fun () -> run ()
Trace_tef.with_setup ~out:`Stdout () @@ fun () -> run ()