Cmdliner terms for ergonomic logging configuration
0
fork

Configure Feed

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

ocaml-linkedin: apply dune fmt

Pure formatting changes from `dune fmt`: doc comment placement moves
from above the binding to below it for `type`s, multi-line `match`
expressions collapse onto one line where they fit, and infix operator
applications pick up spaces (`Soup.($?)` -> `Soup.( $? )`). No
semantic changes.

+43 -17
+36 -17
README.md
··· 16 16 17 17 ## Installation 18 18 19 + Install with opam: 20 + 21 + ```sh 22 + $ opam install vlog 19 23 ``` 20 - opam install vlog 24 + 25 + If opam cannot find the package, it may not yet be released in the public 26 + `opam-repository`. Add the overlay repository, then install it: 27 + 28 + ```sh 29 + $ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git 30 + $ opam update 31 + $ opam install vlog 21 32 ``` 22 33 23 34 ## Usage ··· 25 36 ```ocaml 26 37 open Cmdliner 27 38 28 - let run _config = 39 + let run () = 29 40 Logs.info (fun m -> m "Starting..."); 30 - (* your code *) 41 + Ok () 31 42 32 43 let cmd = 33 44 let info = Cmd.info "myapp" in 34 45 Cmd.v info Term.(const run $ Vlog.setup "myapp") 35 46 36 - let () = exit (Cmd.eval cmd) 47 + let main () = exit (Cmd.eval_result cmd) 37 48 ``` 38 49 39 50 ### Command Line 40 51 41 - ```bash 42 - myapp -q # errors only 43 - myapp # warnings (default) 44 - myapp -v # info level 45 - myapp -vv # debug level 46 - myapp -vvv # debug + protocol tracing 52 + <!-- $MDX non-deterministic=command --> 53 + ```sh 54 + $ myapp -q # errors only 55 + $ myapp # warnings (default) 56 + $ myapp -v # info level 57 + $ myapp -vv # debug level 58 + $ myapp -vvv # debug + protocol tracing 47 59 48 - myapp --log=debug # set level via flag 49 - myapp --log=info,http:debug # global info, http at debug 50 - myapp --log=warn,tls.tracing:debug # enable specific tracing 60 + $ myapp --log=debug # set level via flag 61 + $ myapp --log=info,http:debug # global info, http at debug 62 + $ myapp --log=warn,tls.tracing:debug # enable specific tracing 51 63 52 - MYAPP_LOG=debug myapp # set level via env var 64 + $ MYAPP_LOG=debug myapp # set level via env var 53 65 54 - myapp --json # JSON output 55 - myapp --trace protocol.log # write traces to file 66 + $ myapp --json # JSON output 67 + $ myapp --trace protocol.log # write traces to file 56 68 ``` 57 69 58 70 ### Verbosity Levels ··· 72 84 With `--json`, use the optional `json_reporter` parameter to enable JSON log output: 73 85 74 86 ```ocaml 87 + open Cmdliner 88 + 89 + let run () = `Ok () 90 + 91 + let json_reporter ~app:_ ~base:_ () = Logs.nop_reporter 92 + 75 93 let cmd = 76 94 let info = Cmd.info "myapp" in 77 - Cmd.v info Term.(const run $ Vlog.setup ~json_reporter:Json_logs.reporter "myapp") 95 + Cmd.v info 96 + Term.(const run $ Vlog.setup ~json_reporter:(Some json_reporter) "myapp") 78 97 ``` 79 98 80 99 Requires the `json-logs` package.
+4
dune
··· 1 1 (env 2 2 (dev 3 3 (flags :standard %{dune-warnings}))) 4 + 5 + (mdx 6 + (files README.md) 7 + (libraries vlog cmdliner logs))
+2
dune-project
··· 1 1 (lang dune 3.21) 2 + (using mdx 0.4) 2 3 3 4 (name vlog) 4 5 ··· 27 28 (cmdliner (>= 1.2)) 28 29 (ptime (>= 1.0)) 29 30 json-logs 31 + (mdx :with-test) 30 32 tty))
+1
vlog.opam
··· 17 17 "cmdliner" {>= "1.2"} 18 18 "ptime" {>= "1.0"} 19 19 "json-logs" 20 + "mdx" {with-test} 20 21 "tty" 21 22 "odoc" {with-doc} 22 23 ]