packages feed

log 0.5.4 → 0.5.5

raw patch · 3 files changed

+36/−4 lines, 3 filesdep ~aeson-prettydep ~bloodhounddep ~text-showPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: aeson-pretty, bloodhound, text-show

API changes (from Hackage documentation)

+ Log.Backend.Text: withSimpleTextLogger :: (Logger -> IO r) -> IO (Text, r)

Files

log.cabal view
@@ -1,5 +1,5 @@ name:                log-version:             0.5.4+version:             0.5.5 synopsis:            Structured logging solution with multiple backends  description:         A library that provides a way to record structured@@ -36,6 +36,7 @@                        Log.Backend.PostgreSQL,                        Log.Backend.StandardOutput,                        Log.Backend.StandardOutput.Bulk,+                       Log.Backend.Text,                        Log.Class,                        Log.Data,                        Log.Internal.Logger,@@ -44,7 +45,7 @@    build-depends:       base <5,                        aeson >=0.6.2.0,-                       aeson-pretty >=0.8,+                       aeson-pretty >=0.8.2,                        base64-bytestring,                        bloodhound,                        bytestring,
src/Log/Backend/StandardOutput.hs view
@@ -21,7 +21,7 @@   logger <- stdoutLogger   (act logger) `finally` (do { waitForLogger logger; shutdownLogger logger; }) -{-# DEPRECATED simpleStdoutLogger "Use 'withSimpleStdoutLogger'" #-}+{-# DEPRECATED simpleStdoutLogger "Use 'withSimpleStdOutLogger'" #-}  -- | Simple, synchronous logger that prints messages to standard output. simpleStdoutLogger :: Logger@@ -31,7 +31,7 @@   , loggerShutdown     = return ()   } -{-# DEPRECATED stdoutLogger "Use 'withSimpleStdoutLogger'" #-}+{-# DEPRECATED stdoutLogger "Use 'withSimpleStdOutLogger'" #-}  -- | Create a logger that prints messages to standard output. stdoutLogger :: IO Logger
+ src/Log/Backend/Text.hs view
@@ -0,0 +1,31 @@+-- | A logger that produces in-memory 'Text' values. Mainly useful for+-- testing.+module Log.Backend.Text ( withSimpleTextLogger ) where++import Control.Applicative+import Data.IORef+import Data.Monoid+import Prelude+import qualified Data.Text as T+import qualified Data.Text.Lazy as L+import qualified Data.Text.Lazy.Builder as B++import Log.Data+import Log.Internal.Logger++-- | Create an in-memory logger for the duration of the given action,+-- returning both the result of the action and the logger's output as+-- a 'Text' value afterwards.+withSimpleTextLogger :: (Logger -> IO r) -> IO (T.Text, r)+withSimpleTextLogger act = do+  builderRef <- newIORef mempty+  let logger = Logger+        { loggerWriteMessage = \msg -> do+            let msg' = B.fromText $ showLogMessage Nothing msg+            modifyIORef' builderRef (<> msg' <> B.fromText "\n")+        , loggerWaitForWrite = return ()+        , loggerShutdown     = return ()+        }+  r <- act logger+  txt <- L.toStrict . B.toLazyText <$> readIORef builderRef+  return (txt, r)