packages feed

logging-effect-extra-handler (empty) → 1.0.0

raw patch · 12 files changed

+587/−0 lines, 12 filesdep +basedep +exceptionsdep +logging-effectsetup-changed

Dependencies added: base, exceptions, logging-effect, logging-effect-extra-handler, time, wl-pprint-text

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Change log++## 1.0.0++* Initial release
+ LICENSE.md view
@@ -0,0 +1,23 @@+[The MIT License (MIT)][]++Copyright (c) 2017 Jason Shipman++Permission is hereby granted, free of charge, to any person obtaining a copy of+this software and associated documentation files (the "Software"), to deal in+the Software without restriction, including without limitation the rights to+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies+of the Software, and to permit persons to whom the Software is furnished to do+so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.++[The MIT License (MIT)]: https://opensource.org/licenses/MIT
+ README.md view
@@ -0,0 +1,57 @@+# [logging-effect-extra-handler][]++## Synopsis++```haskell+{-# 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))+```++## Usage via `stack`++``` sh+# 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++# Run the `iso8601plus-handler` example+stack exec iso8601plus-handler++# Run the `rfc822-handler` example+stack exec rfc822-handler+```++[logging-effect-extra-handler]: https://github.com/jship/logging-effect-extra
+ Setup.hs view
@@ -0,0 +1,4 @@+import qualified Distribution.Simple++main :: IO ()+main = Distribution.Simple.defaultMain
+ executable/dispatch-handler-with-iso8601.hs view
@@ -0,0 +1,27 @@+{-# 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 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.dispatchHandler stdoutHandler stderrHandler)
+ executable/iso8601-handler.hs view
@@ -0,0 +1,24 @@+{-# 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.runLoggingT app (Log.iso8601Handler stdoutHandler . Log.renderWithSeverity id)
+ executable/iso8601plus-handler.hs view
@@ -0,0 +1,24 @@+{-# 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.runLoggingT app (Log.iso8601PlusHandler stdoutHandler . Log.renderWithSeverity id)
+ executable/rfc822-handler.hs view
@@ -0,0 +1,24 @@+{-# 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.runLoggingT app (Log.rfc822Handler stdoutHandler . Log.renderWithSeverity id)
+ library/Control/Monad/Log/Extra/Handler.hs view
@@ -0,0 +1,203 @@+module Control.Monad.Log.Extra.Handler+  ( -- * Getting Started+    -- $intro++    -- ** Quickstart using stdout handler+    -- $quickStartStdoutHandler++    -- ** Quickstart using a timestamp handler+    -- $quickStartTimestampHandler++    -- ** Quickstart using dispatch handler+    -- $quickStartDispatchHandler++    -- ** Quickstart using dispatch handler with timestamps+    -- $quickStartDispatchHandlerWithTimestamps++    -- * Convenience handler combinators+    -- $convenience++    -- ** Timestamp handlers+    iso8601Handler+  , iso8601PlusHandler+  , rfc822Handler++    -- ** Dispatch handlers+  , dispatchHandler++    -- ** Shortcuts for stdout/stderr handlers+  , withStdoutHandler+  , withStderrHandler+  , withCustomStdoutHandler+  , withCustomStderrHandler++    -- * Utilities+  , customTimestampHandler+  , withCustomHandler+  ) where++import Control.Monad.IO.Class (MonadIO)+import Control.Monad.Catch (MonadMask)+import Control.Monad.Log (BatchingOptions, Handler, Severity(..), WithSeverity(..))+import qualified Control.Monad.Log as Log+import Data.Time (UTCTime)+import qualified Data.Time as Time+import System.IO (Handle)+import qualified System.IO as IO+import Text.PrettyPrint.Leijen.Text (Doc)++-- | Converts an existing handler into a handler that renders an ISO8601+-- (i.e. YYYY-MM-DDTHH:MM:SS) timestamp on every log message.+iso8601Handler :: (MonadIO m, MonadMask m) => Handler m Doc -> Handler m Doc+iso8601Handler = customTimestampHandler formatter where+  formatter = Time.formatTime Time.defaultTimeLocale "%Y-%m-%dT%H:%M:%S"++-- | Converts an existing handler into a handler that renders an ISO8601+-- (i.e. YYYY-MM-DDTHH:MM:SS with decimal point and fraction of second)+-- timestamp on every log message.+iso8601PlusHandler :: (MonadIO m, MonadMask m)+                   => Handler m Doc+                   -> Handler m Doc+iso8601PlusHandler = customTimestampHandler formatter where+  formatter = Time.formatTime Time.defaultTimeLocale "%Y-%m-%dT%H:%M:%S%Q"++-- | Converts an existing handler into a handler that renders an RFC822+-- timestamp on every log message.+rfc822Handler :: (MonadIO m, MonadMask m) => Handler m Doc -> Handler m Doc+rfc822Handler = customTimestampHandler formatter where+  formatter = Time.formatTime Time.defaultTimeLocale Time.rfc822DateFormat++-- | Converts an existing handler into a handler that renders a timestamp on+-- every log message. The timestamp is formatted via the input function.+customTimestampHandler :: (MonadIO m, MonadMask m)+                       => (UTCTime -> String)+                       -> Handler m Doc+                       -> Handler m Doc+customTimestampHandler formatter handler = \msg -> do+  msg' <- Log.timestamp msg+  handler (Log.renderWithTimestamp formatter id 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.+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+      handler = case msgSeverity msg of+        Emergency     -> stderrHandler+        Alert         -> stderrHandler+        Critical      -> stderrHandler+        Error         -> stderrHandler+        Warning       -> stdoutHandler+        Notice        -> stdoutHandler+        Informational -> stdoutHandler+        Debug         -> stdoutHandler+   in handler msg'++-- | 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++-- | Convenience wrapper around 'Log.withFDHandler' for 'IO.stderr' with somewhat sensible defaults.+withStderrHandler :: (MonadIO m, MonadMask m) => (Handler m Doc -> m a) -> m a+withStderrHandler = withCustomStderrHandler Log.defaultBatchingOptions 0.4 80++-- | Convenience wrapper around 'Log.withFDHandler' for 'IO.stdout'.+withCustomStdoutHandler :: (MonadIO m, MonadMask m)+                        => BatchingOptions+                        -> Float -- ^ The @ribbonFrac@ parameter to 'Pretty.renderPretty'+                        -> Int -- ^ The amount of characters per line. Lines longer than this will be pretty-printed across multiple lines if possible.+                        -> (Handler m Doc -> m a)+                        -> m a+withCustomStdoutHandler = withCustomHandler IO.stdout++-- | Convenience wrapper around 'Log.withFDHandler' for 'IO.stderr'.+withCustomStderrHandler :: (MonadIO m, MonadMask m)+                        => BatchingOptions+                        -> Float -- ^ The @ribbonFrac@ parameter to 'Pretty.renderPretty'+                        -> Int -- ^ The amount of characters per line. Lines longer than this will be pretty-printed across multiple lines if possible.+                        -> (Handler m Doc -> m a)+                        -> m a+withCustomStderrHandler = withCustomHandler IO.stderr++-- | Convenience wrapper around 'Log.withFDHandler' that enables partially+-- applying the 'Handle' as the first parameter.+withCustomHandler :: (MonadIO m, MonadMask m)+                  => Handle+                  -> BatchingOptions+                  -> Float -- ^ The @ribbonFrac@ parameter to 'Pretty.renderPretty'+                  -> Int -- ^ The amount of characters per line. Lines longer than this will be pretty-printed across multiple lines if possible.+                  -> (Handler m Doc -> m a)+                  -> m a+withCustomHandler handle options ribbonFrac width = Log.withFDHandler options handle ribbonFrac width++{- $intro++@logging-effect-extra-handle@ supplements [logging-effect](https://github.com/ocharles/logging-effect)+with convenience handler combinators.++In the quickstart examples, please assume the following is in scope:++@+app :: 'Log.MonadLog' ('WithSeverity' 'Doc') m => m ()+app = 'Log.logWarning' "Cargo number 2331 has commandeered the vessel"+@++-}++{- $quickStartStdoutHandler++@+main :: IO ()+main = 'withStdoutHandler' $ \stdoutHandler ->+  'Log.runLoggingT' app (stdoutHandler . 'Log.renderWithSeverity' id)+@++-}++{- $quickStartTimestampHandler++@+main :: IO ()+main = 'withStdoutHandler' $ \stdoutHandler ->+  'Log.runLoggingT' app ('iso8601Handler' stdoutHandler . 'Log.renderWithSeverity' id)+@++-}++{- $quickStartDispatchHandler++@+main :: IO ()+main =+  'withStdoutHandler' $ \stdoutHandler ->+  'withStderrHandler' $ \stderrHandler ->+  'Log.runLoggingT' app ('dispatchHandler' stdoutHandler stderrHandler)+@++-}++{- $quickStartDispatchHandlerWithTimestamps++@+main :: IO ()+main =+  'withStdoutHandler' $ \stdoutHandler ->+  'withStderrHandler' $ \stderrHandler ->+  'Log.runLoggingT' app ('dispatchHandler' ('iso8601Handler' stdoutHandler) ('iso8601Handler' stderrHandler))+@++-}++{- $convenience++@logging-effect-extra-handler@ provides combinators for:++* producing timestamping handlers from existing handlers+* convenience handlers for 'IO.stdout' and 'IO.stderr'+* dispatching handler to route messages to non-error and error handlers++-}
+ logging-effect-extra-handler.cabal view
@@ -0,0 +1,100 @@+-- This file has been generated from package.yaml by hpack version 0.17.1.+--+-- see: https://github.com/sol/hpack++name:           logging-effect-extra-handler+version:        1.0.0+synopsis:       Handy logging handler combinators+description:    Handy logging handler combinators.+category:       Other+homepage:       https://github.com/jship/logging-effect-extra#readme+bug-reports:    https://github.com/jship/logging-effect-extra/issues+author:         Jason Shipman+maintainer:     Jason Shipman+license:        MIT+build-type:     Simple+cabal-version:  >= 1.10++extra-source-files:+    CHANGELOG.md+    LICENSE.md+    package.yaml+    README.md++source-repository head+  type: git+  location: https://github.com/jship/logging-effect-extra++library+  hs-source-dirs:+      library+  ghc-options: -Wall+  build-depends:+      base >=4.8 && <4.11+    , logging-effect >= 1.1.0 && <1.3+    , wl-pprint-text >=1.1.0.4 && <1.2+    , exceptions >= 0.8.0.2 && <0.9+    , time >=1.5 && <1.9+  exposed-modules:+      Control.Monad.Log.Extra.Handler+  default-language: Haskell2010++executable dispatch-handler+  main-is: dispatch-handler.hs+  hs-source-dirs:+      executable+  ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N+  build-depends:+      base >=4.8 && <4.11+    , logging-effect >= 1.1.0 && <1.3+    , wl-pprint-text >=1.1.0.4 && <1.2+    , logging-effect-extra-handler+  default-language: Haskell2010++executable dispatch-handler-with-iso8601+  main-is: dispatch-handler-with-iso8601.hs+  hs-source-dirs:+      executable+  ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N+  build-depends:+      base >=4.8 && <4.11+    , logging-effect >= 1.1.0 && <1.3+    , wl-pprint-text >=1.1.0.4 && <1.2+    , logging-effect-extra-handler+  default-language: Haskell2010++executable iso8601-handler+  main-is: iso8601-handler.hs+  hs-source-dirs:+      executable+  ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N+  build-depends:+      base >=4.8 && <4.11+    , logging-effect >= 1.1.0 && <1.3+    , wl-pprint-text >=1.1.0.4 && <1.2+    , logging-effect-extra-handler+  default-language: Haskell2010++executable iso8601plus-handler+  main-is: iso8601plus-handler.hs+  hs-source-dirs:+      executable+  ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N+  build-depends:+      base >=4.8 && <4.11+    , logging-effect >= 1.1.0 && <1.3+    , wl-pprint-text >=1.1.0.4 && <1.2+    , logging-effect-extra-handler+  default-language: Haskell2010++executable rfc822-handler+  main-is: rfc822-handler.hs+  hs-source-dirs:+      executable+  ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N+  build-depends:+      base >=4.8 && <4.11+    , logging-effect >= 1.1.0 && <1.3+    , wl-pprint-text >=1.1.0.4 && <1.2+    , logging-effect-extra-handler+  default-language: Haskell2010
+ package.yaml view
@@ -0,0 +1,70 @@+author: Jason Shipman+category: Other+dependencies:+- base >=4.8 && <4.11+- logging-effect >= 1.1.0 && <1.3+- wl-pprint-text >=1.1.0.4 && <1.2+description: Handy logging handler combinators.+executables:+  dispatch-handler:+    dependencies:+    - logging-effect-extra-handler+    ghc-options:+    - -rtsopts+    - -threaded+    - -with-rtsopts=-N+    main: dispatch-handler.hs+    source-dirs: executable+  dispatch-handler-with-iso8601:+    dependencies:+    - logging-effect-extra-handler+    ghc-options:+    - -rtsopts+    - -threaded+    - -with-rtsopts=-N+    main: dispatch-handler-with-iso8601.hs+    source-dirs: executable+  iso8601-handler:+    dependencies:+    - logging-effect-extra-handler+    ghc-options:+    - -rtsopts+    - -threaded+    - -with-rtsopts=-N+    main: iso8601-handler.hs+    source-dirs: executable+  iso8601plus-handler:+    dependencies:+    - logging-effect-extra-handler+    ghc-options:+    - -rtsopts+    - -threaded+    - -with-rtsopts=-N+    main: iso8601plus-handler.hs+    source-dirs: executable+  rfc822-handler:+    dependencies:+    - logging-effect-extra-handler+    ghc-options:+    - -rtsopts+    - -threaded+    - -with-rtsopts=-N+    main: rfc822-handler.hs+    source-dirs: executable+extra-source-files:+- CHANGELOG.md+- LICENSE.md+- package.yaml+- README.md+ghc-options: -Wall+github: jship/logging-effect-extra+library:+  dependencies:+  - exceptions >= 0.8.0.2 && <0.9+  - time >=1.5 && <1.9+  source-dirs: library+license: MIT+maintainer: Jason Shipman+name: logging-effect-extra-handler+synopsis: Handy logging handler combinators+version: '1.0.0'