rio 0.1.11.0 → 0.1.12.0
raw patch · 5 files changed
+27/−4 lines, 5 files
Files
- ChangeLog.md +4/−0
- README.md +1/−1
- rio.cabal +2/−2
- src/RIO/Prelude/Logger.hs +13/−1
- test/RIO/LoggerSpec.hs +7/−0
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for rio +## 0.1.12.0++* Add `logFormat` and `setLogFormat` for `LogOptions`.+ ## 0.1.11.0 * Replace atomic and durable file writing functions with the ones from `unliftio`, see [#167](https://github.com/commercialhaskell/rio/pull/167)
README.md view
@@ -208,7 +208,7 @@ * `-Wpartial-fields` * `-Wredundant-constraints` -You may add them per file, or to your package.yaml, or pass them on+You may add them per file, or to your `package.yaml`, or pass them on the command line when running ghc. We include these in the project template's `package.yaml` file.
rio.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 2a45e44bfde95330afa0baab193dbd03b0e1065480a3a90f4d1b5cc5de3a4556+-- hash: 7dc639bd135a48a7ddeeaf2a43e7de51ccc95f000475f44c042aaa133defb453 name: rio-version: 0.1.11.0+version: 0.1.12.0 synopsis: A standard library for Haskell description: See README and Haddocks at <https://www.stackage.org/package/rio> category: Control
src/RIO/Prelude/Logger.hs view
@@ -19,6 +19,7 @@ , setLogUseTime , setLogUseColor , setLogUseLoc+ , setLogFormat -- ** Standard logging functions , logDebug , logInfo@@ -287,6 +288,7 @@ , logUseTime = False , logUseColor = False , logUseLoc = False+ , logFormat = id , logSend = \new -> atomicModifyIORef' ref $ \old -> (old <> new, ()) } return (ref, options)@@ -324,6 +326,7 @@ , logUseColor = verbose && terminal #endif , logUseLoc = verbose+ , logFormat = id , logSend = \builder -> if useUtf8 && unicode then hPutBuilder handle' (builder <> flush)@@ -425,6 +428,7 @@ , logUseTime :: !Bool , logUseColor :: !Bool , logUseLoc :: !Bool+ , logFormat :: !(Utf8Builder -> Utf8Builder) , logSend :: !(Builder -> IO ()) } @@ -498,6 +502,14 @@ setLogUseLoc :: Bool -> LogOptions -> LogOptions setLogUseLoc l options = options { logUseLoc = l } +-- | Set format method for messages+--+-- Default: `id`+--+-- @since 0.1.12.0+setLogFormat :: (Utf8Builder -> Utf8Builder) -> LogOptions -> LogOptions+setLogFormat f options = options { logFormat = f }+ simpleLogFunc :: LogOptions -> CallStack -> LogSource -> LogLevel -> Utf8Builder -> IO () simpleLogFunc lo cs _src level msg = do logLevel <- logMinLevel lo@@ -509,7 +521,7 @@ timestamp <> getLevel logVerbose <> ansi reset <>- msg <>+ logFormat lo msg <> getLoc <> ansi reset <> "\n"
test/RIO/LoggerSpec.hs view
@@ -67,3 +67,10 @@ noLogging $ logInfo "should not appear" builder <- readIORef ref toLazyByteString builder `shouldBe` "[info] should appear\n"+ it "setLogFormat" $ do+ (ref, options) <- logOptionsMemory+ let format = ("[context] " <>)+ withLogFunc (options & setLogFormat format) $ \lf -> runRIO lf $ do+ logInfo "should be formatted"+ builder <- readIORef ref+ toLazyByteString builder `shouldBe` "[context] should be formatted\n"