Cmdliner terms for ergonomic logging configuration
0
fork

Configure Feed

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

Add cram tests for CLI flags

+102
+66
test/cli.t/run.t
··· 1 + Test vlog CLI flags 2 + 3 + $ export NO_COLOR=1 4 + 5 + Default: warning level, tracing silenced 6 + $ ../test_cli.exe 2>&1 7 + test_cli: [WARNING] warning message 8 + 9 + Quiet mode: errors only 10 + $ ../test_cli.exe -q 2>&1 11 + test_cli: [ERROR] error message 12 + 13 + Verbose: info level 14 + $ ../test_cli.exe -v 2>&1 15 + test_cli: [WARNING] warning message 16 + test_cli: [INFO] info message 17 + 18 + Very verbose: debug level (tracing still silenced) 19 + $ ../test_cli.exe -vv 2>&1 20 + test_cli: [WARNING] warning message 21 + test_cli: [INFO] info message 22 + test_cli: [DEBUG] debug message 23 + 24 + Triple verbose: debug + tracing enabled 25 + $ ../test_cli.exe -vvv 2>&1 26 + test_cli: [WARNING] warning message 27 + test_cli: [INFO] info message 28 + test_cli: [DEBUG] debug message 29 + test_cli: [DEBUG] trace message 30 + 31 + Using --log flag for global level 32 + $ ../test_cli.exe --log=error 2>&1 33 + test_cli: [ERROR] error message 34 + 35 + $ ../test_cli.exe --log=info 2>&1 36 + test_cli: [WARNING] warning message 37 + test_cli: [INFO] info message 38 + 39 + Using --log flag for per-source override 40 + $ ../test_cli.exe --log=warning,test:debug 2>&1 41 + test_cli: [WARNING] warning message 42 + test_cli: [DEBUG] debug message 43 + 44 + Enable tracing via --log 45 + $ ../test_cli.exe --log=warning,test.tracing:debug 2>&1 46 + test_cli: [WARNING] warning message 47 + test_cli: [DEBUG] trace message 48 + 49 + Combined: global + per-source 50 + $ ../test_cli.exe --log=debug,test.tracing:warning 2>&1 51 + test_cli: [WARNING] warning message 52 + test_cli: [INFO] info message 53 + test_cli: [DEBUG] debug message 54 + 55 + Environment variable 56 + $ TEST_LOG=info ../test_cli.exe 2>&1 57 + test_cli: [WARNING] warning message 58 + test_cli: [INFO] info message 59 + 60 + Help output shows all flags 61 + $ ../test_cli.exe --help=plain 2>&1 | grep -E '^\s+(-q|--quiet|-v|--verbose|--log|--json|--trace)' 62 + -q, --quiet 63 + -v, --verbose 64 + --json 65 + --log=SPEC 66 + --trace=FILE
+6
test/dune
··· 1 + (executable 2 + (name test_cli) 3 + (libraries vlog logs)) 4 + 5 + (cram 6 + (deps test_cli.exe))
+30
test/test_cli.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 + SPDX-License-Identifier: MIT 4 + ---------------------------------------------------------------------------*) 5 + 6 + (** Test CLI for vlog cram tests. *) 7 + 8 + open Cmdliner 9 + 10 + (* Create a test log source *) 11 + let src = Logs.Src.create "test" ~doc:"Test source" 12 + module Log = (val Logs.src_log src : Logs.LOG) 13 + 14 + (* Create a tracing source *) 15 + let tracing_src = Logs.Src.create "test.tracing" ~doc:"Test tracing source" 16 + module Trace = (val Logs.src_log tracing_src : Logs.LOG) 17 + 18 + let run _config = 19 + Log.err (fun m -> m "error message"); 20 + Log.warn (fun m -> m "warning message"); 21 + Log.info (fun m -> m "info message"); 22 + Log.debug (fun m -> m "debug message"); 23 + Trace.debug (fun m -> m "trace message") 24 + 25 + let cmd = 26 + let doc = "Test CLI for vlog" in 27 + let info = Cmd.info "test-cli" ~doc in 28 + Cmd.v info Term.(const run $ Vlog.setup "test") 29 + 30 + let () = exit (Cmd.eval cmd)