packages feed

logging-effect-extra-handler 1.0.0 → 1.1.0

raw patch · 9 files changed

+114/−92 lines, 9 filesnew-component:exe:route-handlernew-component:exe:route-handler-with-iso8601PVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.Monad.Log.Extra.Handler: routeHandler :: (MonadIO m, MonadMask m) => Handler m Doc -> Handler m Doc -> (a -> Doc) -> Handler m (WithSeverity a)

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Change log +## 1.1.0++* Add `routeHandler`+* Deprecate `dispatchHandler`+ ## 1.0.0  * Initial release
README.md view
@@ -28,8 +28,9 @@ main =   Log.withStdoutHandler $ \stdoutHandler ->   Log.withStderrHandler $ \stderrHandler ->-  Log.runLoggingT app (Log.dispatchHandler (Log.iso8601Handler stdoutHandler)-                                           (Log.iso8601Handler stderrHandler))+  Log.runLoggingT app (Log.routeHandler (Log.iso8601Handler stdoutHandler)+                                        (Log.iso8601Handler stderrHandler)+                                        id) ```  ## Usage via `stack`@@ -38,12 +39,6 @@ # Build the project. stack build -# Run the `dispatch-handler-with-iso8601` example-stack exec dispatch-handler-with-iso8601--# Run the `dispatch-handler` example-stack exec dispatch-handler- # Run the `iso8601-handler` example stack exec iso8601-handler @@ -52,6 +47,12 @@  # Run the `rfc822-handler` example stack exec rfc822-handler++# Run the `route-handler-with-iso8601` example+stack exec route-handler-with-iso8601++# Run the `route-handler` example+stack exec route-handler ```  [logging-effect-extra-handler]: https://github.com/jship/logging-effect-extra
− executable/dispatch-handler-with-iso8601.hs
@@ -1,27 +0,0 @@-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE OverloadedStrings #-}--module Main (main) where--import Control.Monad.Log (MonadLog, WithSeverity)-import qualified Control.Monad.Log as Log-import qualified Control.Monad.Log.Extra.Handler as Log-import Text.PrettyPrint.Leijen.Text (Doc)--app :: MonadLog (WithSeverity Doc) m => m ()-app = do-  Log.logEmergency "GAH! All systems are down!!!"-  Log.logAlert "Red alert!"-  Log.logCritical "Critical hit!"-  Log.logError "Errors abound!"-  Log.logWarning "Cargo number 2331 has commandeered the vessel"-  Log.logNotice "Heads up, but it's no biggie."-  Log.logInfo "Does anyone read these?"-  Log.logDebug "Sleuthing with log messages..."--main :: IO ()-main =-  Log.withStdoutHandler $ \stdoutHandler ->-  Log.withStderrHandler $ \stderrHandler ->-  Log.runLoggingT app (Log.dispatchHandler (Log.iso8601Handler stdoutHandler)-                                           (Log.iso8601Handler stderrHandler))
− executable/dispatch-handler.hs
@@ -1,26 +0,0 @@-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE OverloadedStrings #-}--module Main (main) where--import Control.Monad.Log (MonadLog, WithSeverity)-import qualified Control.Monad.Log as Log-import qualified Control.Monad.Log.Extra.Handler as Log-import Text.PrettyPrint.Leijen.Text (Doc)--app :: MonadLog (WithSeverity Doc) m => m ()-app = do-  Log.logEmergency "GAH! All systems are down!!!"-  Log.logAlert "Red alert!"-  Log.logCritical "Critical hit!"-  Log.logError "Errors abound!"-  Log.logWarning "Cargo number 2331 has commandeered the vessel"-  Log.logNotice "Heads up, but it's no biggie."-  Log.logInfo "Does anyone read these?"-  Log.logDebug "Sleuthing with log messages..."--main :: IO ()-main =-  Log.withStdoutHandler $ \stdoutHandler ->-  Log.withStderrHandler $ \stderrHandler ->-  Log.runLoggingT app (Log.dispatchHandler stdoutHandler stderrHandler)
+ executable/route-handler-with-iso8601.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE OverloadedStrings #-}++module Main (main) where++import Control.Monad.Log (MonadLog, WithSeverity)+import qualified Control.Monad.Log as Log+import qualified Control.Monad.Log.Extra.Handler as Log+import Text.PrettyPrint.Leijen.Text (Doc)++app :: MonadLog (WithSeverity Doc) m => m ()+app = do+  Log.logEmergency "GAH! All systems are down!!!"+  Log.logAlert "Red alert!"+  Log.logCritical "Critical hit!"+  Log.logError "Errors abound!"+  Log.logWarning "Cargo number 2331 has commandeered the vessel"+  Log.logNotice "Heads up, but it's no biggie."+  Log.logInfo "Does anyone read these?"+  Log.logDebug "Sleuthing with log messages..."++main :: IO ()+main =+  Log.withStdoutHandler $ \stdoutHandler ->+  Log.withStderrHandler $ \stderrHandler ->+  Log.runLoggingT app (Log.routeHandler (Log.iso8601Handler stdoutHandler)+                                        (Log.iso8601Handler stderrHandler)+                                        id)
+ executable/route-handler.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE OverloadedStrings #-}++module Main (main) where++import Control.Monad.Log (MonadLog, WithSeverity)+import qualified Control.Monad.Log as Log+import qualified Control.Monad.Log.Extra.Handler as Log+import Text.PrettyPrint.Leijen.Text (Doc)++app :: MonadLog (WithSeverity Doc) m => m ()+app = do+  Log.logEmergency "GAH! All systems are down!!!"+  Log.logAlert "Red alert!"+  Log.logCritical "Critical hit!"+  Log.logError "Errors abound!"+  Log.logWarning "Cargo number 2331 has commandeered the vessel"+  Log.logNotice "Heads up, but it's no biggie."+  Log.logInfo "Does anyone read these?"+  Log.logDebug "Sleuthing with log messages..."++main :: IO ()+main =+  Log.withStdoutHandler $ \stdoutHandler ->+  Log.withStderrHandler $ \stderrHandler ->+  Log.runLoggingT app (Log.routeHandler stdoutHandler stderrHandler id)
library/Control/Monad/Log/Extra/Handler.hs view
@@ -8,11 +8,11 @@     -- ** Quickstart using a timestamp handler     -- $quickStartTimestampHandler -    -- ** Quickstart using dispatch handler-    -- $quickStartDispatchHandler+    -- ** Quickstart using routing handler+    -- $quickStartRoutingHandler -    -- ** Quickstart using dispatch handler with timestamps-    -- $quickStartDispatchHandlerWithTimestamps+    -- ** Quickstart using routing handler with timestamps+    -- $quickStartRoutingHandlerWithTimestamps      -- * Convenience handler combinators     -- $convenience@@ -22,7 +22,8 @@   , iso8601PlusHandler   , rfc822Handler -    -- ** Dispatch handlers+    -- ** Routing handlers+  , routeHandler   , dispatchHandler      -- ** Shortcuts for stdout/stderr handlers@@ -80,12 +81,13 @@ -- | Basic dispatch handler that routes 'Warning', 'Notice', 'Informational', -- and 'Debug' messages to the first input handler and routes 'Emergency', -- 'Alert', 'Critical', and 'Error' messages to the second input handler.-dispatchHandler :: (MonadIO m, MonadMask m)-                => Handler m Doc -- ^ The handler for non-error messages (i.e. stdout handler)-                -> Handler m Doc -- ^ The handler for error messages (i.e. stderr handler)-                -> Handler m (WithSeverity Doc)-dispatchHandler stdoutHandler stderrHandler = \msg ->-  let msg' = Log.renderWithSeverity id msg+routeHandler :: (MonadIO m, MonadMask m)+             => Handler m Doc -- ^ The handler for non-error messages (i.e. stdout handler)+             -> Handler m Doc -- ^ The handler for error messages (i.e. stderr handler)+             -> (a -> Doc)    -- ^ How to render+             -> Handler m (WithSeverity a)+routeHandler stdoutHandler stderrHandler renderer = \msg ->+  let msg' = Log.renderWithSeverity renderer msg       handler = case msgSeverity msg of         Emergency     -> stderrHandler         Alert         -> stderrHandler@@ -97,6 +99,19 @@         Debug         -> stdoutHandler    in handler msg' +-- | Basic dispatch handler that routes 'Warning', 'Notice', 'Informational',+-- and 'Debug' messages to the first input handler and routes 'Emergency',+-- 'Alert', 'Critical', and 'Error' messages to the second input handler.+-- This function is limiting as it assumes incoming messages are+-- 'WithSeverity' 'Doc' instead of the more general 'WithSeverity' 'a'.+dispatchHandler :: (MonadIO m, MonadMask m)+                => Handler m Doc -- ^ The handler for non-error messages (i.e. stdout handler)+                -> Handler m Doc -- ^ The handler for error messages (i.e. stderr handler)+                -> Handler m (WithSeverity Doc)+dispatchHandler stdoutHandler stderrHandler =+  routeHandler stdoutHandler stderrHandler id+{-# DEPRECATED dispatchHandler "dispatchHandler is deprecated in favor of routeHandler." #-}+ -- | Convenience wrapper around 'Log.withFDHandler' for 'IO.stdout' with somewhat sensible defaults. withStdoutHandler :: (MonadIO m, MonadMask m) => (Handler m Doc -> m a) -> m a withStdoutHandler = withCustomStdoutHandler Log.defaultBatchingOptions 0.4 80@@ -168,26 +183,26 @@  -} -{- $quickStartDispatchHandler+{- $quickStartRoutingHandler  @ main :: IO () main =   'withStdoutHandler' $ \stdoutHandler ->   'withStderrHandler' $ \stderrHandler ->-  'Log.runLoggingT' app ('dispatchHandler' stdoutHandler stderrHandler)+  'Log.runLoggingT' app ('routeHandler' stdoutHandler stderrHandler 'id') @  -} -{- $quickStartDispatchHandlerWithTimestamps+{- $quickStartRoutingHandlerWithTimestamps  @ main :: IO () main =   'withStdoutHandler' $ \stdoutHandler ->   'withStderrHandler' $ \stderrHandler ->-  'Log.runLoggingT' app ('dispatchHandler' ('iso8601Handler' stdoutHandler) ('iso8601Handler' stderrHandler))+  'Log.runLoggingT' app ('routeHandler' ('iso8601Handler' stdoutHandler) ('iso8601Handler' stderrHandler) 'id') @  -}
logging-effect-extra-handler.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           logging-effect-extra-handler-version:        1.0.0+version:        1.1.0 synopsis:       Handy logging handler combinators description:    Handy logging handler combinators. category:       Other@@ -39,8 +39,8 @@       Control.Monad.Log.Extra.Handler   default-language: Haskell2010 -executable dispatch-handler-  main-is: dispatch-handler.hs+executable iso8601-handler+  main-is: iso8601-handler.hs   hs-source-dirs:       executable   ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N@@ -51,8 +51,8 @@     , logging-effect-extra-handler   default-language: Haskell2010 -executable dispatch-handler-with-iso8601-  main-is: dispatch-handler-with-iso8601.hs+executable iso8601plus-handler+  main-is: iso8601plus-handler.hs   hs-source-dirs:       executable   ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N@@ -63,8 +63,8 @@     , logging-effect-extra-handler   default-language: Haskell2010 -executable iso8601-handler-  main-is: iso8601-handler.hs+executable rfc822-handler+  main-is: rfc822-handler.hs   hs-source-dirs:       executable   ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N@@ -75,8 +75,8 @@     , logging-effect-extra-handler   default-language: Haskell2010 -executable iso8601plus-handler-  main-is: iso8601plus-handler.hs+executable route-handler+  main-is: route-handler.hs   hs-source-dirs:       executable   ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N@@ -87,8 +87,8 @@     , logging-effect-extra-handler   default-language: Haskell2010 -executable rfc822-handler-  main-is: rfc822-handler.hs+executable route-handler-with-iso8601+  main-is: route-handler-with-iso8601.hs   hs-source-dirs:       executable   ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N
package.yaml view
@@ -6,23 +6,23 @@ - wl-pprint-text >=1.1.0.4 && <1.2 description: Handy logging handler combinators. executables:-  dispatch-handler:+  route-handler:     dependencies:     - logging-effect-extra-handler     ghc-options:     - -rtsopts     - -threaded     - -with-rtsopts=-N-    main: dispatch-handler.hs+    main: route-handler.hs     source-dirs: executable-  dispatch-handler-with-iso8601:+  route-handler-with-iso8601:     dependencies:     - logging-effect-extra-handler     ghc-options:     - -rtsopts     - -threaded     - -with-rtsopts=-N-    main: dispatch-handler-with-iso8601.hs+    main: route-handler-with-iso8601.hs     source-dirs: executable   iso8601-handler:     dependencies:@@ -67,4 +67,4 @@ maintainer: Jason Shipman name: logging-effect-extra-handler synopsis: Handy logging handler combinators-version: '1.0.0'+version: '1.1.0'