Skip to content

Commit

Permalink
log: add pretty printer module
Browse files Browse the repository at this point in the history
Because the debug module doesn't use best practices, pretty-printers using the
Format module are not ergonomic to use when they are needed for constructing
loglines.

Provide a module for adapters, containing Mtime's spans for the time being.

Signed-off-by: Pau Ruiz Safont <[email protected]>
  • Loading branch information
psafont committed Jun 26, 2024
1 parent ad40fd9 commit 44223d1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ocaml/libs/log/debug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,5 @@ functor
try f ()
with e -> log_backtrace_internal ~level:Syslog.Debug ~msg:"debug" e ()
end

module Pp = struct let mtime_span () = Fmt.str "%a" Mtime.Span.pp end
4 changes: 4 additions & 0 deletions ocaml/libs/log/debug.mli
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ module Make : functor (_ : BRAND) -> DEBUG
val is_disabled : string -> Syslog.level -> bool
(** [is_disabled brand level] returns [true] if logging for [brand] at [level]
is disabled, * otherwise returns [false]. *)

module Pp : sig
val mtime_span : unit -> Mtime.Span.t -> string
end
2 changes: 2 additions & 0 deletions ocaml/libs/log/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
(names syslog_stubs))
(libraries
astring
fmt
mtime
logs
threads.posix
xapi-backtrace
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi-guard/lib/disk_cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ end = struct
let* failed = retry true in
( if failed then
let elapsed = Mtime_clock.count counter in
D.debug "%s: Pushed %s after trying for %s" __FUN
D.debug "%s: Pushed %s after trying for %a" __FUN
(print_key (uuid, timestamp, key))
(Fmt.to_to_string Mtime.Span.pp elapsed)
Debug.Pp.mtime_span elapsed
) ;
Lwt.return_unit

Expand Down

0 comments on commit 44223d1

Please sign in to comment.