Skip to content

Commit

Permalink
simplify runLoggerLoggingT by defining in terms of runLogAction
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed May 31, 2024
1 parent 8ec3b04 commit 4129016
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/Blammo/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,12 @@ import Control.Monad.IO.Unlift (MonadUnliftIO)
import Control.Monad.Logger.Aeson
import Data.Aeson (Series)
import Data.Aeson.Types (Pair)
import Data.ByteString (ByteString)
import UnliftIO.Exception (finally)

runLoggerLoggingT
:: (MonadUnliftIO m, HasLogger env) => env -> LoggingT m a -> m a
runLoggerLoggingT env f = (`finally` flushLogStr logger) $ do
runLoggingT
(filterLogger (getLoggerShouldLog logger) f)
(loggerOutput logger $ getLoggerReformat logger)
runLoggingT f $ \loc source level msg ->
runLogAction logger loc source level msg
where
logger = env ^. loggerL

loggerOutput
:: Logger
-> (LogLevel -> ByteString -> ByteString)
-> Loc
-> LogSource
-> LogLevel
-> LogStr
-> IO ()
loggerOutput logger reformat =
defaultOutputWith $ defaultOutputOptions $ \logLevel bytes -> do
pushLogStrLn logger $ toLogStr $ reformat logLevel bytes

0 comments on commit 4129016

Please sign in to comment.