From 46f1ba26ff5ed8914091d34488605c60f1855266 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Mon, 1 Dec 2025 14:22:34 +0100 Subject: refactor: setup Log package in main --- 2025/ocaml/bin/dune | 4 +++- 2025/ocaml/bin/main.ml | 15 ++++++++++++++- 2025/ocaml/lib/domain/dune | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/2025/ocaml/bin/dune b/2025/ocaml/bin/dune index 49a288c..3903f3b 100644 --- a/2025/ocaml/bin/dune +++ b/2025/ocaml/bin/dune @@ -5,4 +5,6 @@ domain application infrastructure - presentation)) + presentation + logs + logs.fmt)) diff --git a/2025/ocaml/bin/main.ml b/2025/ocaml/bin/main.ml index f34d5ef..cbfe6d2 100644 --- a/2025/ocaml/bin/main.ml +++ b/2025/ocaml/bin/main.ml @@ -1,3 +1,16 @@ -let main () = Presentation.Cli.run () +let env_log_level = + match Sys.getenv_opt "LOG_LEVEL" with + | None -> + Some Logs.Warning + | Some lvl -> ( + match Logs.level_of_string lvl with Error _ -> None | Ok v -> v ) + +let main () = + let log_level = env_log_level in + Logs.set_level log_level ; + Logs.set_reporter (Logs_fmt.reporter ()) ; + Logs.info (fun m -> + m "Started application with LOG_LEVEL=%s" (Logs.level_to_string log_level) ) ; + Presentation.Cli.run () let () = if !Sys.interactive then () else exit (main ()) diff --git a/2025/ocaml/lib/domain/dune b/2025/ocaml/lib/domain/dune index 038c1bf..5b13d31 100644 --- a/2025/ocaml/lib/domain/dune +++ b/2025/ocaml/lib/domain/dune @@ -1,6 +1,9 @@ (library (name domain) (inline_tests) + (libraries + fmt + logs) (preprocess (pps ppx_deriving.show -- cgit v1.2.3