module Imm.Logger.Simple (module Imm.Logger.Simple, module Reexport) where
import Imm.Logger as Reexport
import Imm.Prelude
import Imm.Pretty
import System.Log.FastLogger as Reexport
data LoggerSettings = LoggerSettings
{ loggerSet :: LoggerSet
, errorLoggerSet :: LoggerSet
, logLevel :: LogLevel
, colorizeLogs :: Bool
}
defaultLogger :: MonadIO m => m LoggerSettings
defaultLogger = io $ LoggerSettings
<$> newStdoutLoggerSet defaultBufSize
<*> newStderrLoggerSet defaultBufSize
<*> pure Info
<*> pure True
mkCoLogger :: (MonadIO m) => LoggerSettings -> CoLoggerF m LoggerSettings
mkCoLogger settings = CoLoggerF coLog coGetLevel coSetLevel coSetColorize coFlush where
coLog Error t = do
io $ pushLogStrLn (errorLoggerSet settings) $ toLogStr $ (show :: Doc -> String) $ handleColor $ red t
return settings
coLog l t = do
when (l >= logLevel settings) $ io $ pushLogStrLn (loggerSet settings) $ toLogStr $ (show :: Doc -> String) $ handleColor t
return settings
coGetLevel = return (logLevel settings, settings)
coSetLevel l = return $ settings { logLevel = l }
coSetColorize c = return $ settings { colorizeLogs = c }
coFlush = do
io $ flushLogStr $ loggerSet settings
io $ flushLogStr $ errorLoggerSet settings
return settings
handleColor = if colorizeLogs settings then id else plain