git.iko.soy/typeable/control-logger
on master help sign in
Merge pull request #6 from typeable/ville/b2b-3112-scrub-the-context
de19de8Ville Tirronen
src/Control/Logger/Internal.hs+16−2
@@ -17,7 +17,7 @@ module Control.Logger.Internal
17import Control.Has
17import Control.Has
18import Control.Lens
18import Control.Lens
19import Control.DeepSeq
19import Control.DeepSeq
20−import Data.Aeson (ToJSON, FromJSON, Object)
20+import Data.Aeson (ToJSON, FromJSON, Object, Value(..))
21import Data.Text (Text)
21import Data.Text (Text)
22import Data.Monoid
22import Data.Monoid
23import GHC.Stack
23import GHC.Stack
@@ -79,4 +79,18 @@ logMsgWith logger s t =
79 liftIO $ runLogger logger callStack s t
79 liftIO $ runLogger logger callStack s t
80
80
81runLogger :: Logger -> CallStack -> LogSeverity -> Text -> IO ()
81runLogger :: 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