logging-effect 1.3.2 → 1.3.3
raw patch · 3 files changed
+21/−12 lines, 3 filesdep ~basedep ~stm
Dependency ranges changed: base, stm
Files
- Changelog.md +9/−0
- logging-effect.cabal +3/−3
- src/Control/Monad/Log.hs +9/−9
Changelog.md view
@@ -1,3 +1,12 @@+## 1.3.3 -- 2018-09-30++### Other Changes++* Support `stm-2.5`.+* Support `base-4.12`.++---+ ## 1.3.2 -- 2018-07-06 ### Other Changes
logging-effect.cabal view
@@ -1,5 +1,5 @@ name: logging-effect-version: 1.3.2+version: 1.3.3 synopsis: A mtl-style monad transformer for general purpose & compositional logging homepage: https://github.com/ocharles/logging-effect license: BSD3@@ -13,7 +13,7 @@ library exposed-modules: Control.Monad.Log other-extensions: ViewPatterns, OverloadedStrings, GeneralizedNewtypeDeriving, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, FunctionalDependencies, PatternSynonyms- build-depends: base >=4.8 && <4.12+ build-depends: base >=4.8 && <4.13 , async >=2.0 && <2.3 , transformers >=0.4 && <0.6 , text >=1.2 && <1.3@@ -21,7 +21,7 @@ , mtl >= 2.2.1 && <2.3 , exceptions >= 0.8.0.2 && <0.11 , free >= 4.12.1 && < 5.2- , stm >= 2.4.4.1 && < 2.5+ , stm >= 2.4.4.1 && < 2.6 , stm-delay >= 0.1.1.1 && < 0.2 , prettyprinter >= 1.2 && < 1.3 , monad-control >= 1.0.0.4 && < 1.1
src/Control/Monad/Log.hs view
@@ -483,7 +483,7 @@ -> io a withBatchedHandler BatchingOptions{..} flush k = do closed <- liftIO (newTVarIO False)- channel <- liftIO (newTBQueueIO flushMaxQueueSize)+ channel <- liftIO (newTBQueueIO (fromIntegral flushMaxQueueSize)) bracket (liftIO (async (repeatWhileTrue (publish closed channel)))) (\publisher -> do liftIO (do atomically (writeTVar closed True)@@ -616,7 +616,7 @@ -- 'discardLogging' is: -- -- @--- 'discardLogging' :: 'DiscardLoggingT' messsage m a -> m a+-- 'discardLogging' :: 'DiscardLoggingT' message m a -> m a -- @ newtype DiscardLoggingT message m a = DiscardLoggingT {discardLogging :: m a -- ^ Run a 'MonadLog' computation by throwing away all log requests.@@ -744,7 +744,7 @@ wrapped in 'WithSeverity'. @-testApp :: 'MonadLog' ('WithSeverity' 'PP.Doc') m => m ()+testApp :: 'MonadLog' ('WithSeverity' ('PP.Doc' ann)) m => m () testApp = do logMessage ('WithSeverity' 'Informational' "Don't mind me") logMessage ('WithSeverity' 'Error' "But do mind me!")@@ -840,29 +840,29 @@ have some older code that doesn't yet have any severity information: @-legacyCode :: 'MonadLog' 'PP.Doc' m => m ()+legacyCode :: 'MonadLog' ('PP.Doc' ann) m => m () legacyCode = 'logMessage' "Does anyone even remember writing this function?" @ Here @legacyCode@ is only logging 'PP.Doc', while our @testApp@ is logging 'WithSeverity' 'PP.Doc'. What happens if we compose these programs? ->>> :t testApp >> legacyCode- Couldn't match type ‘Doc’ with ‘WithSeverity Doc’+>>> :t runLoggingT (testApp >> legacyCode) (const (pure ()))+ Couldn't match type ‘WithSeverity (Doc ann1)’ with '(Doc ann0)' Whoops! 'MonadLog' has /functional dependencies/ on the type class which means that there can only be a single way to log per monad. One solution might be to 'lift' one set of logs into the other: ->>> :t testApp >> lift legacyCode- :: (MonadTrans t, MonadLog Doc m, MonadLog (WithSeverity Doc) (t m)) => t m ()+>>> :t runLoggingT (testApp >> lift legacyCode) (const (pure ()))+ :: MonadLog (Doc ann) m => m () And indeed, this is /a/ solution, but it's not a particularly nice one. Instead, we can map both of these computations into a common log format: >>> :t mapLogMessage Left testApp >> mapLogMessage Right (logMessage "Hello")- :: (MonadLog (Either (WithSeverity Doc) Doc) m) => m ()+ :: (MonadLog (Either (WithSeverity (Doc ann)) (Doc ann)) m) => m () This is a trivial way of combining two different types of log message. In larger applications you will probably want to define a new sum-type that combines all of