-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove some lesser-used reexports from Blammo.Logging (#54)
added new ThreadContext and Setup modules
- Loading branch information
1 parent
ca12432
commit f6c62fd
Showing
14 changed files
with
110 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters