Cmdliner terms for ergonomic logging configuration
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-vlog: enable MDX on lib/vlog.mli, fix broken doc example

Run mdx on lib/vlog.mli so the {[ ... ]} odoc blocks now type-check.

The Quick Start example used `(* your args *)` as a placeholder for
extra Cmdliner subterms; replaced with a concrete `let run_app () =
()` plus the Vlog.setup term, dropping the placeholder.

The Verbosity Levels block was a markdown table -- not OCaml -- so
moved from {[ ... ]} to {v ... v}.

The Test Setup example called Alcotest.run "mylib" Test_foo.suite at
the top level, where Test_foo.suite was undefined. Wrapped in `let
run () = ...` so the toploop defines the test entrypoint without
actually invoking Alcotest.run (which would hang reading argv at mdx
test time), and replaced Test_foo.suite with the empty list so the
example shows real types.

+17 -7
+4
lib/dune
··· 12 12 ptime.clock.os 13 13 json-logs 14 14 nox-tty)) 15 + 16 + (mdx 17 + (files vlog.mli) 18 + (libraries vlog cmdliner logs alcotest))
+13 -7
lib/vlog.mli
··· 14 14 {2 Quick Start} 15 15 16 16 {[ 17 - let cmd = 18 - let info = Cmd.info "myapp" in 19 - Cmd.v info Term.(const run $ Vlog.setup "myapp" $ (* your args *)) 17 + let run_app () = 18 + Logs.app (fun m -> m "myapp started"); 19 + Logs.info (fun m -> m "config loaded") 20 + 21 + let cmd = 22 + let open Cmdliner in 23 + Cmd.v (Cmd.info "myapp") 24 + Cmdliner.Term.(const run_app $ Vlog.setup "myapp") 20 25 ]} 21 26 22 27 {2 Command Line Usage} ··· 31 36 32 37 {2 Verbosity Levels} 33 38 34 - {[ 39 + {v 35 40 | Flag | Level | *.tracing sources | 36 41 |--------|---------|-------------------| 37 42 | -q | Error | Silenced | ··· 39 44 | -v | Info | Silenced | 40 45 | -vv | Debug | Silenced | 41 46 | -vvv | Debug | Enabled | 42 - ]} *) 47 + v} *) 43 48 44 49 (** {1 Setup} *) 45 50 ··· 151 156 152 157 In [test.ml]: 153 158 {[ 154 - let () = Vlog.setup_test ~level:Logs.Debug () 155 - let () = Alcotest.run "mylib" Test_foo.suite 159 + let run () = 160 + Vlog.setup_test ~level:Logs.Debug (); 161 + Alcotest.run "mylib" [] 156 162 ]} 157 163 158 164 Run with reduced noise: