Skip to content

Commit

Permalink
missing feature in logger
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Apr 1, 2024
1 parent cd59372 commit e883ff6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core/logger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions src/core/logger.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down

0 comments on commit e883ff6

Please sign in to comment.