Skip to content

Commit

Permalink
Add withLoggerEnv (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin authored Jun 3, 2024
1 parent e4879ce commit b2e52ec
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Blammo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Blammo
version: 1.2.0.0
version: 1.2.1.0
maintainer: Freckle Education
category: Utils
github: freckle/blammo
Expand Down
2 changes: 1 addition & 1 deletion src/Blammo/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Blammo/Logging/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/Blammo/Logging/Simple.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- | Simplified out-of-the-box logging
module Blammo.Logging.Simple
( newLoggerEnv
, withLoggerEnv
, runSimpleLoggingT
, module Blammo.Logging
) where
Expand All @@ -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
Expand Down

0 comments on commit b2e52ec

Please sign in to comment.