From 58d165a4156336473a9f8bbe0f55823d0b973fc2 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Fri, 5 Dec 2025 01:50:42 +0100 Subject: feat(logger): implement logger functor still needs to be injected somehow --- 2025/ocaml/lib/application/logger.ml | 39 ++++++++++++++++++++++++++++++++++++ 2025/ocaml/lib/infrastructure/log.ml | 32 ++++++++++------------------- 2 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 2025/ocaml/lib/application/logger.ml (limited to '2025/ocaml/lib') diff --git a/2025/ocaml/lib/application/logger.ml b/2025/ocaml/lib/application/logger.ml new file mode 100644 index 0000000..3d63201 --- /dev/null +++ b/2025/ocaml/lib/application/logger.ml @@ -0,0 +1,39 @@ +module type LoggerType = sig + type 'a t + + val app : 'a t -> unit + + val err : 'a t -> unit + + val warn : 'a t -> unit + + val info : 'a t -> unit + + val debug : 'a t -> unit +end + +module type S = sig + type 'a t + + val app : 'a t -> unit + + val err : 'a t -> unit + + val warn : 'a t -> unit + + val info : 'a t -> unit + + val debug : 'a t -> unit +end + +module Make (Logger : LoggerType) : S with type 'a t := 'a Logger.t = struct + let app = Logger.app + + let err = Logger.err + + let warn = Logger.warn + + let info = Logger.info + + let debug = Logger.debug +end diff --git a/2025/ocaml/lib/infrastructure/log.ml b/2025/ocaml/lib/infrastructure/log.ml index 60f52b5..a15c1e7 100644 --- a/2025/ocaml/lib/infrastructure/log.ml +++ b/2025/ocaml/lib/infrastructure/log.ml @@ -1,25 +1,15 @@ -type level = App | Err | Warning | Info | Debug +module LogsAdapter = struct + type 'a t = ('a, unit) Logs.msgf -let log = function - | App -> - Logs.app - | Err -> - Logs.err - | Warning -> - Logs.warn - | Info -> - Logs.info - | Debug -> - Logs.debug + let app msgf = Logs.app msgf -(** [pp_passthrough pp x] is [x] with the side-effects - caused by calling [pp] on [x]. *) -let pp_passthrough pp x = pp x ; x + let err msgf = Logs.err msgf -(** [pp_list lvl msg lst] prints all elements of [lst] with the - message [msg] at the level [lvl] *) -let pp_list lvl msg = List.iter (fun elmt -> log lvl (fun m -> m msg elmt)) + let warn msgf = Logs.warn msgf -(** [pp_sequence lvl msg seq] prints all elements of [seq] with the - message [msg] at the level [lvl] *) -let pp_sequence lvl msg = Seq.iter (fun elmt -> log lvl (fun m -> m msg elmt)) + let info msgf = Logs.info msgf + + let debug msgf = Logs.debug msgf +end + +module Logger = Application.Logger.Make (LogsAdapter) -- cgit v1.2.3