From 20a2217d864d2c758e86bbb8e14f7426c28ea5b5 Mon Sep 17 00:00:00 2001 From: Ethan Brown Date: Fri, 20 Feb 2026 11:43:43 -0800 Subject: [PATCH 1/2] Expose option for adding timestamps to logger Requested by @tjschutte. - Does not change API for existing dependants; defaults to False - Exposes option to add timestamp to logs --- ambar-hs-utils/src/Util/Logger.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ambar-hs-utils/src/Util/Logger.hs b/ambar-hs-utils/src/Util/Logger.hs index e2a8170..17092ef 100644 --- a/ambar-hs-utils/src/Util/Logger.hs +++ b/ambar-hs-utils/src/Util/Logger.hs @@ -116,13 +116,26 @@ serialised (Logger f) = Logger $ \msg -> standardLogger :: Logger IO Text standardLogger = Logger $ Text.hPutStrLn stderr +data LoggerOpts = LoggerOpts + { withTimestamps :: Bool + } + +defaultLoggerOpts :: LoggerOpts +defaultLoggerOpts = LoggerOpts + { withTimestamps = False + } + -- | Log up to a set log level, including location for errors and debugging. -- Serializes all logs, making it not suitable for high performance logging. plainLogger :: Severity -> SimpleLogger -plainLogger maxSeverity = +plainLogger maxSeverity = plainLoggerWith maxSeverity defaultLoggerOpts + +plainLoggerWith :: Severity -> LoggerOpts -> SimpleLogger +plainLoggerWith maxSeverity opts = filterM (\(WithSeverity s _) -> s <= maxSeverity) $ - enhance prettify $ - serialised standardLogger + if withTimestamps opts + then enhanceM withTimeStamp $ enhance prettify $ serialised standardLogger + else enhance prettify $ serialised standardLogger prettify :: Pretty a => a -> Text prettify = renderStrict . layoutSmart defaultLayoutOptions . pretty From 12f1e1c954c75e56322692c9a56b954dcbfcfea3 Mon Sep 17 00:00:00 2001 From: Ethan Brown Date: Fri, 20 Feb 2026 16:25:47 -0800 Subject: [PATCH 2/2] Removed configuration; timestamps always! Per Marcelo's PR feedback. --- ambar-hs-utils/src/Util/Logger.hs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/ambar-hs-utils/src/Util/Logger.hs b/ambar-hs-utils/src/Util/Logger.hs index 17092ef..1c95b9a 100644 --- a/ambar-hs-utils/src/Util/Logger.hs +++ b/ambar-hs-utils/src/Util/Logger.hs @@ -116,26 +116,14 @@ serialised (Logger f) = Logger $ \msg -> standardLogger :: Logger IO Text standardLogger = Logger $ Text.hPutStrLn stderr -data LoggerOpts = LoggerOpts - { withTimestamps :: Bool - } - -defaultLoggerOpts :: LoggerOpts -defaultLoggerOpts = LoggerOpts - { withTimestamps = False - } - -- | Log up to a set log level, including location for errors and debugging. -- Serializes all logs, making it not suitable for high performance logging. plainLogger :: Severity -> SimpleLogger -plainLogger maxSeverity = plainLoggerWith maxSeverity defaultLoggerOpts - -plainLoggerWith :: Severity -> LoggerOpts -> SimpleLogger -plainLoggerWith maxSeverity opts = +plainLogger maxSeverity = filterM (\(WithSeverity s _) -> s <= maxSeverity) $ - if withTimestamps opts - then enhanceM withTimeStamp $ enhance prettify $ serialised standardLogger - else enhance prettify $ serialised standardLogger + enhanceM withTimeStamp $ + enhance prettify $ + serialised standardLogger prettify :: Pretty a => a -> Text prettify = renderStrict . layoutSmart defaultLayoutOptions . pretty