From 088f2a5e7fd8a1d92d342204ee54b8325ce38ae1 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 12 Jun 2023 13:30:06 -0400 Subject: [PATCH] trace-tef: additional argument to `with_setup`; env for "stdout"/"stderr" --- src/tef/trace_tef.ml | 4 +++- src/tef/trace_tef.mli | 15 ++++++++++----- test/t1.ml | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tef/trace_tef.ml b/src/tef/trace_tef.ml index 16181e8..9131613 100644 --- a/src/tef/trace_tef.ml +++ b/src/tef/trace_tef.ml @@ -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 diff --git a/src/tef/trace_tef.mli b/src/tef/trace_tef.mli index 6134782..5385e37 100644 --- a/src/tef/trace_tef.mli +++ b/src/tef/trace_tef.mli @@ -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. +*) (**/**) diff --git a/test/t1.ml b/test/t1.ml index 2874fa7..a1b25fa 100644 --- a/test/t1.ml +++ b/test/t1.ml @@ -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 ()