@@ -16,14 +16,12 @@ module Control.Logger.Internal
1616
1717import Control.Has
1818import Control.Lens
19+import Control.Monad.IO.Class
1920import Control.DeepSeq
20−import Data.Aeson (ToJSON, FromJSON, Object)
21+import Data.Aeson (ToJSON, FromJSON, Object, Value(..))
2122import Data.Text (Text)
2223import Data.Monoid
2324import GHC.Stack
24−#if MIN_VERSION_mtl(2,3,0)
25−import Control.Monad.IO.Class
26−#endif
2725
2826
2927data LogSeverity
@@ -79,4 +77,18 @@ logMsgWith logger s t =
7977 liftIO $ runLogger logger callStack s t
8078
8179runLogger :: Logger -> CallStack -> LogSeverity -> Text -> IO ()
82−runLogger (Logger ctx theScrubber logger) cs ls txt = logger ctx cs ls (appEndo theScrubber txt)
80+runLogger (Logger ctx theScrubber logger) cs ls txt
81+ = logger (scrubContext theScrubber ctx) cs ls (appEndo theScrubber txt)
82+
83+
84+scrubContext :: Endo Text -> Object -> Object
85+scrubContext theScrubber = fmap doScrub
86+ where
87+ doScrub :: Value -> Value
88+ doScrub = \case
89+ Object object -> Object (fmap doScrub object)
90+ Array array -> Array (fmap doScrub array)
91+ String string -> String (appEndo theScrubber string)
92+ n@Number{} -> n
93+ b@Bool{} -> b
94+ n@Null -> n