From e883ff6e544658230e4f385d85ef8f8dcd4bfee1 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 1 Apr 2024 10:26:33 -0400 Subject: [PATCH] missing feature in logger --- src/core/logger.ml | 6 +++--- src/core/logger.mli | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/logger.ml b/src/core/logger.ml index 8f462621..8668e91f 100644 --- a/src/core/logger.ml +++ b/src/core/logger.ml @@ -3,14 +3,14 @@ module Sync_queue = Moonpool.Blocking_queue type level = Log_level.t [@@deriving show, eq] -let setup_level ?debug ?log_level () = +let setup_level ?(default_level = Info) ?debug ?log_level () = let lvl = match debug, log_level, Sys.getenv_opt "DEBUG" with | Some true, _, _ -> Debug | _, Some lvl, _ -> lvl - | Some false, _, _ -> Info + | Some false, _, _ -> default_level | None, None, Some _ -> Debug - | _ -> Info + | _ -> default_level in Logs.set_level ~all:true (Some lvl) diff --git a/src/core/logger.mli b/src/core/logger.mli index 16296c5d..0a151f60 100644 --- a/src/core/logger.mli +++ b/src/core/logger.mli @@ -44,11 +44,13 @@ val with_no_logger : unit -> (unit -> 'a) -> 'a (** [with_no_logger () f] calls [f()] in a context where there is no logger. Useful to avoid logging loops. *) -val setup_level : ?debug:bool -> ?log_level:level -> unit -> unit +val setup_level : + ?default_level:level -> ?debug:bool -> ?log_level:level -> unit -> unit (** Setup log level. It will use [Info] by default, unless the env var ["DEBUG"] is set or [~debug] or [~log_level] is passed. - [debug] takes precedence over [log_level] which takes precedence over the env. *) + [debug] takes precedence over [log_level] which takes precedence over the env. + @param default_level the level used if nothing is specified *) val setup_logger_to_stdout : unit -> unit (** Setup a logger that emits on stdout *)