From b2e52ec797a84dbe2bd076e6609c65cdcfc0a908 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Mon, 3 Jun 2024 13:40:31 -0600 Subject: [PATCH] Add withLoggerEnv (#45) --- Blammo.cabal | 2 +- CHANGELOG.md | 6 +++++- package.yaml | 2 +- src/Blammo/Logging.hs | 2 +- src/Blammo/Logging/Logger.hs | 2 +- src/Blammo/Logging/Simple.hs | 8 ++++++++ 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Blammo.cabal b/Blammo.cabal index d1b2537..73a711b 100644 --- a/Blammo.cabal +++ b/Blammo.cabal @@ -5,7 +5,7 @@ cabal-version: 1.18 -- see: https://github.com/sol/hpack name: Blammo -version: 1.2.0.0 +version: 1.2.1.0 synopsis: Batteries-included Structured Logging library description: Please see README.md category: Utils diff --git a/CHANGELOG.md b/CHANGELOG.md index d363d15..9cdaa25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -## [_Unreleased_](https://github.com/freckle/blammo/compare/v1.2.0.0...main) +## [_Unreleased_](https://github.com/freckle/blammo/compare/v1.2.1.0...main) + +## [v1.2.1.0](https://github.com/freckle/blammo/compare/1.2.0.0...v1.2.1.0) + +- Add `Blammo.Logging.Simple.withLoggerEnv` ## [v1.2.0.0](https://github.com/freckle/blammo/compare/v1.1.3.0...v1.2.0.0) diff --git a/package.yaml b/package.yaml index 4d0c4d9..e1813a8 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: Blammo -version: 1.2.0.0 +version: 1.2.1.0 maintainer: Freckle Education category: Utils github: freckle/blammo diff --git a/src/Blammo/Logging.hs b/src/Blammo/Logging.hs index f2cb0e1..37ff2d5 100644 --- a/src/Blammo/Logging.hs +++ b/src/Blammo/Logging.hs @@ -68,7 +68,7 @@ import Data.Aeson (Series) import Data.Aeson.Types (Pair) import UnliftIO.Exception (finally) --- | Initialize logging, pass a 'Logger' to the callback, and clean up at the end. +-- | Initialize logging, pass a 'Logger' to the callback, and clean up at the end -- -- Applications should avoid calling this more than once in their lifecycle. runLoggerLoggingT diff --git a/src/Blammo/Logging/Logger.hs b/src/Blammo/Logging/Logger.hs index d0666ad..c70932e 100644 --- a/src/Blammo/Logging/Logger.hs +++ b/src/Blammo/Logging/Logger.hs @@ -54,7 +54,7 @@ import System.Log.FastLogger.Compat import UnliftIO (MonadUnliftIO) import UnliftIO.Exception (finally, throwString) --- | Initialize logging, pass a 'Logger' to the callback, and clean up at the end. +-- | Initialize logging, pass a 'Logger' to the callback, and clean up at the end -- -- Applications should avoid calling this more than once in their lifecycle. withLogger :: MonadUnliftIO m => LogSettings -> (Logger -> m a) -> m a diff --git a/src/Blammo/Logging/Simple.hs b/src/Blammo/Logging/Simple.hs index e144ee8..4a21dc8 100644 --- a/src/Blammo/Logging/Simple.hs +++ b/src/Blammo/Logging/Simple.hs @@ -1,6 +1,7 @@ -- | Simplified out-of-the-box logging module Blammo.Logging.Simple ( newLoggerEnv + , withLoggerEnv , runSimpleLoggingT , module Blammo.Logging ) where @@ -16,6 +17,13 @@ import Control.Monad.IO.Unlift (MonadUnliftIO) newLoggerEnv :: MonadIO m => m Logger newLoggerEnv = liftIO $ newLogger =<< Env.parse +-- | Initialize logging (configured via environment variables), +-- pass a 'Logger' to the callback, and clean up at the end +-- +-- Applications should avoid calling this more than once in their lifecycle. +withLoggerEnv :: MonadUnliftIO m => (Logger -> m a) -> m a +withLoggerEnv f = liftIO Env.parse >>= \logger -> withLogger logger f + -- | Construct a 'Logger' configured via environment variables and use it runSimpleLoggingT :: MonadUnliftIO m => LoggingT m a -> m a runSimpleLoggingT f = do