@@ -3,8 +3,6 @@ module Control.Logger
33 ( Logger
44 , loggerContext
55 , scrubber
6− , censor
7− , censorWith
86 , logMsg
97 , logMsgWith
108 , logInfo
@@ -36,7 +34,6 @@ module Control.Logger
3634 , st
3735 , ToObject(..)
3836 , withScrubber
39− , censoringWith
4037 , censoring
4138 ) where
4239
@@ -44,9 +41,7 @@ import Control.Has
4441import Control.Lens hiding (censoring)
4542import Control.Logger.Internal
4643import Control.Logger.Orphans ()
47−import Control.Monad
4844import Control.Monad.Catch
49−import Control.Monad.IO.Class
5045import qualified Data.List as List
5146import Data.Monoid
5247import Data.Text (Text)
@@ -56,6 +51,10 @@ import GHC.Stack
5651import Katip (ToObject (..))
5752import System.Log.FastLogger
5853import Text.Shakespeare.Text (st)
54+#if MIN_VERSION_mtl(2,3,0)
55+import Control.Monad
56+import Control.Monad.IO.Class
57+#endif
5958
6059logError
6160 :: (LoggingMonad r m)
@@ -109,21 +108,7 @@ logErrorWith
109108 -> m ()
110109logErrorWith logger msg = withFrozenCallStack (logMsgWith logger Error msg)
111110
112−safeReplace :: Text -> Text -> Text -> Text
113−safeReplace what with where_
114− | Text.null what = where_
115− | otherwise = Text.replace what with where_
116−
117−-- | Add a some text to scrubber
118−censorWith :: Text -> Text -> Logger -> Logger
119−censorWith replacement needle l =
120− l & scrubber <>~ Endo (safeReplace needle replacement)
121−
122−-- | Censor with "***"
123−censor :: Text -> Logger -> Logger
124−censor = censorWith "***"
125−
126−-- | Run an action with adjusted scrubber
111+-- | Adjust the scrubbing function.
127112withScrubber
128113 :: forall r m a. (Has Logger r, MonadReader r m)
129114 => (Endo Text -> Endo Text)
@@ -134,24 +119,15 @@ withScrubber scrubF = local expandScrubber
134119 expandScrubber :: r -> r
135120 expandScrubber = over part (over scrubber scrubF)
136121
137−-- | Run an action while censoring additional text from logs
138−censoringWith
139− :: (Has Logger r, MonadReader r m)
140− => Text
141− -> Text
142− -> m a
143− -> m a
144−censoringWith replacement txt = withScrubber (<> censored)
145− where
146− censored = Endo (safeReplace txt replacement)
147−
148122-- | Run an action while censoring additional text from logs
149123censoring
150124 :: (Has Logger r, MonadReader r m)
151125 => Text
152126 -> m a
153127 -> m a
154−censoring = censoringWith "***"
128+censoring txt = withScrubber (<> censored)
129+ where
130+ censored = Endo (Text.replace txt "XXXX")
155131
156132-- | Log exceptions occured in computation and just ignore them.
157133tryLogError