Unverified Commit 381a474c authored by fisx's avatar fisx

Add helper to canonicalize whitespace on a renderer.

parent 9bffbfe3
......@@ -26,6 +26,7 @@ module System.Logger
, setRendererNetstr
, renderDefault
, renderNetstr
, canonicalizeWhitespace
, bufSize
, setBufSize
, name
......
......@@ -25,6 +25,7 @@ module System.Logger.Settings
, setRendererNetstr
, renderDefault
, renderNetstr
, canonicalizeWhitespace
, logLevel
, logLevelMap
, logLevelOf
......@@ -40,6 +41,7 @@ module System.Logger.Settings
) where
import Data.String
import Data.Char (isSpace)
import Data.ByteString (ByteString)
import Data.ByteString.Char8 (pack)
import Data.Map.Strict as Map
......@@ -48,6 +50,7 @@ import Data.UnixTime
import System.Log.FastLogger (defaultBufSize)
import System.Logger.Message
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.ByteString.Lazy.Builder as B
data Settings = Settings
......@@ -114,6 +117,23 @@ renderDefault s _ _ = renderDefault_ s
renderNetstr :: Renderer
renderNetstr _ _ _ = renderNetstr_
-- | Replace all whitespace characters in the output of a renderer by @' '@.
-- Log output must be ASCII encoding.
--
-- (Many logging processors handle newlines poorly. Instead of hunting down all
-- places and situations in your code and your dependencies that inject newlines
-- into your log messages, you can choose to call 'canonicalizeWhitespace' on
-- your renderer.)
canonicalizeWhitespace :: Renderer -> Renderer
canonicalizeWhitespace rndrRaw delim df lvl
= B.lazyByteString . nl2sp . B.toLazyByteString . rndrRaw delim df lvl
where
nl2sp :: L.ByteString -> L.ByteString
nl2sp = L.concatMap $
\c -> if isSpace c
then " "
else L.singleton c
logLevel :: Settings -> Level
logLevel = _logLevel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment