{-# LANGUAGE OverloadedStrings #-}
module Network.AWS.Internal.Logger
(
Logger
, newLogger
, LogLevel (..)
, logError
, logInfo
, logDebug
, logTrace
, ToLog (..)
, buildLines
) where
import Control.Monad
import Control.Monad.IO.Class
import qualified Data.ByteString.Lazy.Builder as Build
import Data.Monoid
import Network.AWS.Data.Log
import Network.AWS.Types
import System.IO
newLogger :: MonadIO m => LogLevel -> Handle -> m Logger
newLogger x hd = liftIO $ do
hSetBinaryMode hd True
hSetBuffering hd LineBuffering
return $ \y b ->
when (x >= y) $
Build.hPutBuilder hd (b <> "\n")
logError, logInfo, logDebug, logTrace
:: (MonadIO m, ToLog a) => Logger -> a -> m ()
logError f = liftIO . f Error . build
logInfo f = liftIO . f Info . build
logDebug f = liftIO . f Debug . build
logTrace f = liftIO . f Trace . build