Skip to content

Commit

Permalink
Remove some lesser-used reexports from Blammo.Logging (#54)
Browse files Browse the repository at this point in the history
added new ThreadContext and Setup modules
  • Loading branch information
chris-martin authored Aug 1, 2024
1 parent ca12432 commit f6c62fd
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Blammo-wai/Blammo-wai.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-wai
version: 0.0.0.1
version: 0.0.0.2
synopsis: Using Blammo with WAI
description: Please see README.md
category: Logging, Web
Expand Down
6 changes: 5 additions & 1 deletion Blammo-wai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## [_Unreleased_](https://github.com/freckle/blammo/compare/Blammo-wai-v0.0.0.1..main)
## [_Unreleased_](https://github.com/freckle/blammo/compare/Blammo-wai-v0.0.0.2..main)

## [v0.0.0.2](https://github.com/freckle/blammo/compare/Blammo-wai-v0.0.0.1...Blammo-wai-v0.0.0.2)

- Support `Blammo-2.1.0.0`

## [v0.0.0.1](https://github.com/freckle/blammo/compare/Blammo-wai-v0.0.0.0...Blammo-wai-v0.0.0.1)

Expand Down
2 changes: 1 addition & 1 deletion Blammo-wai/README.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Control.Lens (lens)
```haskell
-- Blammo
import Blammo.Logging
import Blammo.Logging.Simple
-- wai
import Network.Wai (Middleware)
Expand Down
2 changes: 1 addition & 1 deletion Blammo-wai/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Blammo-wai
version: 0.0.0.1
version: 0.0.0.2
maintainer: Freckle Education
category: Logging, Web
github: freckle/blammo
Expand Down
2 changes: 2 additions & 0 deletions Blammo-wai/src/Network/Wai/Middleware/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Network.Wai.Middleware.Logging
import Prelude

import Blammo.Logging
import Blammo.Logging.Setup (HasLogger, runWithLogger)
import Blammo.Logging.ThreadContext (Pair, withThreadContext)
import Control.Applicative ((<|>))
import Control.Arrow ((***))
import Control.Monad.IO.Unlift (withRunInIO)
Expand Down
4 changes: 3 additions & 1 deletion Blammo/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: 2.0.0.0
version: 2.1.0.0
synopsis: Batteries-included Structured Logging library
description: Please see README.md
category: Logging
Expand All @@ -32,10 +32,12 @@ library
Blammo.Logging.LogSettings
Blammo.Logging.LogSettings.Env
Blammo.Logging.LogSettings.LogLevels
Blammo.Logging.Setup
Blammo.Logging.Simple
Blammo.Logging.Terminal
Blammo.Logging.Terminal.LogPiece
Blammo.Logging.Test
Blammo.Logging.ThreadContext
Blammo.Logging.WithLogger
Data.Aeson.Compat
System.Log.FastLogger.Compat
Expand Down
24 changes: 23 additions & 1 deletion Blammo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
## [_Unreleased_](https://github.com/freckle/blammo/compare/Blammo-v2.0.0.0...main)
## [_Unreleased_](https://github.com/freckle/blammo/compare/Blammo-v2.2.0.0...main)

## [v2.1.0.0](https://github.com/freckle/blammo/compare/v2.0.0.0...Blammo-v2.1.0.0)

Removes less frequently used definitions from the main `Blammo.Logging` module
into other modules.

- Moved from `Blammo.Logging` to new module `Blammo.Logging.ThreadContext`:
`MonadMask`, `withThreadContext`, `myThreadContext`, `Pair`.
- Removed from `Blammo.Logging` (still available in `Blammo.Logging.LogSettings`):
`LogSettings`, `LogDestination (..)`, `LogFormat (..)`, `defaultLogSettings`,
`LogColor (..)`, `setLogSettingsLevels`, `setLogSettingsDestination`,
`setLogSettingsFormat`, `setLogSettingsColor`, `setLogSettingsBreakpoint`,
`setLogSettingsConcurrency`.
- Moved from `Blammo.Logging` to new module `Blammo.Logging.Setup`:
`HasLogger (..)`, `withLogger`, `newLogger`, `runLoggerLoggingT`, `LoggingT`,
`WithLogger (..)`, `runWithLogger`

`Blammo.Logging.Simple` has been expanded to include reëxports of:

- `Blammo.Logging.LogSettings`
- `Blammo.Logging.Setup`
- `Blammo.Logging.ThreadContext`

## [v2.0.0.0](https://github.com/freckle/blammo/compare/v1.2.1.0...Blammo-v2.0.0.0)

Expand Down
2 changes: 1 addition & 1 deletion Blammo/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Blammo
version: 2.0.0.0
version: 2.1.0.0
maintainer: Freckle Education
category: Logging
github: freckle/blammo
Expand Down
45 changes: 2 additions & 43 deletions Blammo/src/Blammo/Logging.hs
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
module Blammo.Logging
( LogSettings
, LogLevel (..)
, LogDestination (..)
, LogFormat (..)
, LogColor (..)
, defaultLogSettings
, setLogSettingsLevels
, setLogSettingsDestination
, setLogSettingsFormat
, setLogSettingsColor
, setLogSettingsBreakpoint
, setLogSettingsConcurrency
( LogLevel (..)
, Logger
, HasLogger (..)
, withLogger
, newLogger
, runLoggerLoggingT

-- * Re-exports from "Control.Monad.Logger.Aeson"

Expand All @@ -24,18 +9,9 @@ module Blammo.Logging
, (.=)
, Series

-- ** Thread Context
, MonadMask
, withThreadContext
, myThreadContext
, Pair

-- ** Transformers
-- ** Classes
, MonadLogger (..)
, MonadLoggerIO (..)
, LoggingT
, WithLogger (..)
, runWithLogger

-- ** Common logging functions

Expand All @@ -57,23 +33,6 @@ module Blammo.Logging
, logOtherNS
) where

import Blammo.Logging.LogSettings
import Blammo.Logging.Logger
import Blammo.Logging.WithLogger
import Control.Lens (view)
import Control.Monad.Catch (MonadMask)
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Control.Monad.Logger.Aeson
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
--
-- Applications should avoid calling this more than once in their lifecycle.
runLoggerLoggingT
:: (MonadUnliftIO m, HasLogger env) => env -> LoggingT m a -> m a
runLoggerLoggingT env f =
runLoggingT f (runLogAction logger) `finally` flushLogStr logger
where
logger = view loggerL env
51 changes: 51 additions & 0 deletions Blammo/src/Blammo/Logging/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Blammo.Logging.Setup
( HasLogger (..)
, withLogger
, newLogger
, runLoggerLoggingT
, LoggingT
, WithLogger (..)
, runWithLogger
, newLoggerEnv
, withLoggerEnv
, runSimpleLoggingT
) where

import Prelude

import Blammo.Logging
import qualified Blammo.Logging.LogSettings.Env as Env
import Blammo.Logging.Logger
import Blammo.Logging.WithLogger
import Control.Lens (view)
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Control.Monad.Logger.Aeson
import UnliftIO.Exception (finally)

-- | Construct a 'Logger' configured via environment variables
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
logger <- newLoggerEnv
runLoggerLoggingT logger f

-- | 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
:: (MonadUnliftIO m, HasLogger env) => env -> LoggingT m a -> m a
runLoggerLoggingT env f =
runLoggingT f (runLogAction logger) `finally` flushLogStr logger
where
logger = view loggerL env
33 changes: 7 additions & 26 deletions Blammo/src/Blammo/Logging/Simple.hs
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
-- | Simplified out-of-the-box logging
module Blammo.Logging.Simple
( newLoggerEnv
, withLoggerEnv
, runSimpleLoggingT
, module Blammo.Logging
( module Blammo.Logging
, module Blammo.Logging.LogSettings
, module Blammo.Logging.ThreadContext
, module Blammo.Logging.Setup
) where

import Prelude

import Blammo.Logging
import qualified Blammo.Logging.LogSettings.Env as Env
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.IO.Unlift (MonadUnliftIO)

-- | Construct a 'Logger' configured via environment variables
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
logger <- newLoggerEnv
runLoggerLoggingT logger f
import Blammo.Logging.LogSettings
import Blammo.Logging.Setup
import Blammo.Logging.ThreadContext
10 changes: 10 additions & 0 deletions Blammo/src/Blammo/Logging/ThreadContext.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Blammo.Logging.ThreadContext
( MonadMask
, withThreadContext
, myThreadContext
, Pair
) where

import Control.Monad.Catch (MonadMask)
import Control.Monad.Logger.Aeson (myThreadContext, withThreadContext)
import Data.Aeson.Types (Pair)
2 changes: 1 addition & 1 deletion Blammo/tests/Blammo/Logging/LoggerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Blammo.Logging.LoggerSpec

import Prelude

import Blammo.Logging
import Blammo.Logging.Logger
import Blammo.Logging.Simple
import Control.Monad.Reader (runReaderT)
import Data.Aeson (Value (..))
import qualified Data.Aeson.Compat as KeyMap
Expand Down
3 changes: 2 additions & 1 deletion Blammo/tests/Blammo/Logging/TerminalSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Prelude
import Blammo.Logging
import Blammo.Logging.Logger (LoggedMessage (..))
import Blammo.Logging.Terminal
import Data.Aeson
import Data.Aeson (encode, object)
import Data.Aeson.Types (Object, Pair, Value (..))
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
Expand Down

0 comments on commit f6c62fd

Please sign in to comment.