git.iko.soy/typeable/control-logger
on master help sign in
B2B-3112 Scrub the context
commit171cea73765c3014482c170e96e66abcebb3b23d authorVille Tirronen <ville@typeable.io> dateTue 20 May 2025, 09:17 (1 year ago) parent4e31de2
1 file changed+16−2
src/Control/Logger/Internal.hs+16−2
src/Control/Logger/Internal.hs+16−2
@@ -17,7 +17,7 @@ module Control.Logger.Internal
1717import Control.Has
1818import Control.Lens
1919import Control.DeepSeq
20−import Data.Aeson (ToJSON, FromJSON, Object)
20+import Data.Aeson (ToJSON, FromJSON, Object, Value(..))
2121import Data.Text (Text)
2222import Data.Monoid
2323import GHC.Stack
@@ -79,4 +79,18 @@ logMsgWith logger s t =
7979 liftIO $ runLogger logger callStack s t
8080
8181runLogger :: Logger -> CallStack -> LogSeverity -> Text -> IO ()
82−runLogger (Logger ctx theScrubber logger) cs ls txt = logger ctx cs ls (appEndo theScrubber txt)
82+runLogger (Logger ctx theScrubber logger) cs ls txt
83+ = logger (scrubContext theScrubber ctx) cs ls (appEndo theScrubber txt)
84+
85+
86+scrubContext :: Endo Text -> Object -> Object
87+scrubContext theScrubber = fmap doScrub
88+ where
89+ doScrub :: Value -> Value
90+ doScrub = \case
91+ Object object -> Object (fmap doScrub object)
92+ Array array -> Array (fmap doScrub array)
93+ String string -> String (appEndo theScrubber string)
94+ n@Number{} -> n
95+ b@Bool{} -> b
96+ n@Null -> n