@@ -2,6 +2,7 @@
22
33module Katip.Scribes.Handle
44 ( mkHandleScribe
5+ , ColorStrategy (..)
56 ) where
67
78-------------------------------------------------------------------------------
@@ -44,10 +45,20 @@ renderPrim NullPrim = fromByteString "null"
4445
4546
4647-------------------------------------------------------------------------------
47−mkHandleScribe :: Handle -> Severity -> Verbosity -> IO Scribe
48−mkHandleScribe h sev verb = do
48+data ColorStrategy
49+ = ColorLog Bool
50+ -- ^ Whether to use color control chars in log output
51+ | ColorIfTerminal
52+ -- ^ Color if output is a terminal
53+
54+
55+-------------------------------------------------------------------------------
56+mkHandleScribe :: ColorStrategy -> Handle -> Severity -> Verbosity -> IO Scribe
57+mkHandleScribe cs h sev verb = do
4958 hSetBuffering h LineBuffering
50− colorize <- hIsTerminalDevice h
59+ colorize <- case cs of
60+ ColorIfTerminal -> hIsTerminalDevice h
61+ ColorLog b -> return b
5162 return $ Scribe $ \ i@Item{..} -> do
5263 when (itemSeverity >= sev) $
5364 B.hPutStrLn h $ toByteString $ formatItem colorize verb i
@@ -87,7 +98,7 @@ formatItem withColor verb Item{..} =
8798_ioLogEnv :: LogEnv
8899_ioLogEnv = unsafePerformIO $ do
89100 le <- initLogEnv "io" "io"
90− lh <- mkHandleScribe stdout Debug V3
101+ lh <- mkHandleScribe ColorIfTerminal stdout Debug V3
91102 return $ registerScribe "stdout" lh le
92103{-# NOINLINE _ioLogEnv #-}
93104