module Cryptol.Utils.Logger
( Logger
, stdoutLogger
, stderrLogger
, handleLogger
, quietLogger
, funLogger
, logPutStr
, logPutStrLn
, logPrint
) where
import System.IO(Handle, hPutStr, stdout, stderr)
import Control.DeepSeq(NFData(..))
newtype Logger = Logger (String -> IO ())
instance NFData Logger where
rnf (Logger x) = rnf x
logPutStr :: Logger -> String -> IO ()
logPutStr (Logger f) = f
logPutStrLn :: Logger -> String -> IO ()
logPutStrLn l s = logPutStr l (s ++ "\n")
logPrint :: Show a => Logger -> a -> IO ()
logPrint l a = logPutStrLn l (show a)
quietLogger :: Logger
quietLogger = Logger (const (return ()))
handleLogger :: Handle -> Logger
handleLogger h = Logger (hPutStr h)
stdoutLogger :: Logger
stdoutLogger = handleLogger stdout
stderrLogger :: Logger
stderrLogger = handleLogger stderr
funLogger :: (String -> IO ()) -> Logger
funLogger = Logger