katip 0.5.0.4 → 0.5.1.0
raw patch · 5 files changed
+46/−7 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Katip: mkFileScribe :: FilePath -> Severity -> Verbosity -> IO Scribe
+ Katip.Scribes.Handle: mkFileScribe :: FilePath -> Severity -> Verbosity -> IO Scribe
- Katip: itemApp :: forall a_an12. Lens' (Item a_an12) Namespace
+ Katip: itemApp :: forall a_an1k. Lens' (Item a_an1k) Namespace
- Katip: itemEnv :: forall a_an12. Lens' (Item a_an12) Environment
+ Katip: itemEnv :: forall a_an1k. Lens' (Item a_an1k) Environment
- Katip: itemHost :: forall a_an12. Lens' (Item a_an12) HostName
+ Katip: itemHost :: forall a_an1k. Lens' (Item a_an1k) HostName
- Katip: itemLoc :: forall a_an12. Lens' (Item a_an12) (Maybe Loc)
+ Katip: itemLoc :: forall a_an1k. Lens' (Item a_an1k) (Maybe Loc)
- Katip: itemMessage :: forall a_an12. Lens' (Item a_an12) LogStr
+ Katip: itemMessage :: forall a_an1k. Lens' (Item a_an1k) LogStr
- Katip: itemNamespace :: forall a_an12. Lens' (Item a_an12) Namespace
+ Katip: itemNamespace :: forall a_an1k. Lens' (Item a_an1k) Namespace
- Katip: itemPayload :: forall a_an12 a_aqjY. Lens (Item a_an12) (Item a_aqjY) a_an12 a_aqjY
+ Katip: itemPayload :: forall a_an1k a_aqkg. Lens (Item a_an1k) (Item a_aqkg) a_an1k a_aqkg
- Katip: itemProcess :: forall a_an12. Lens' (Item a_an12) ProcessID
+ Katip: itemProcess :: forall a_an1k. Lens' (Item a_an1k) ProcessID
- Katip: itemSeverity :: forall a_an12. Lens' (Item a_an12) Severity
+ Katip: itemSeverity :: forall a_an1k. Lens' (Item a_an1k) Severity
- Katip: itemThread :: forall a_an12. Lens' (Item a_an12) ThreadIdText
+ Katip: itemThread :: forall a_an1k. Lens' (Item a_an1k) ThreadIdText
- Katip: itemTime :: forall a_an12. Lens' (Item a_an12) UTCTime
+ Katip: itemTime :: forall a_an1k. Lens' (Item a_an1k) UTCTime
- Katip.Core: itemApp :: forall a_an12. Lens' (Item a_an12) Namespace
+ Katip.Core: itemApp :: forall a_an1k. Lens' (Item a_an1k) Namespace
- Katip.Core: itemEnv :: forall a_an12. Lens' (Item a_an12) Environment
+ Katip.Core: itemEnv :: forall a_an1k. Lens' (Item a_an1k) Environment
- Katip.Core: itemHost :: forall a_an12. Lens' (Item a_an12) HostName
+ Katip.Core: itemHost :: forall a_an1k. Lens' (Item a_an1k) HostName
- Katip.Core: itemLoc :: forall a_an12. Lens' (Item a_an12) (Maybe Loc)
+ Katip.Core: itemLoc :: forall a_an1k. Lens' (Item a_an1k) (Maybe Loc)
- Katip.Core: itemMessage :: forall a_an12. Lens' (Item a_an12) LogStr
+ Katip.Core: itemMessage :: forall a_an1k. Lens' (Item a_an1k) LogStr
- Katip.Core: itemNamespace :: forall a_an12. Lens' (Item a_an12) Namespace
+ Katip.Core: itemNamespace :: forall a_an1k. Lens' (Item a_an1k) Namespace
- Katip.Core: itemPayload :: forall a_an12 a_aqjY. Lens (Item a_an12) (Item a_aqjY) a_an12 a_aqjY
+ Katip.Core: itemPayload :: forall a_an1k a_aqkg. Lens (Item a_an1k) (Item a_aqkg) a_an1k a_aqkg
- Katip.Core: itemProcess :: forall a_an12. Lens' (Item a_an12) ProcessID
+ Katip.Core: itemProcess :: forall a_an1k. Lens' (Item a_an1k) ProcessID
- Katip.Core: itemSeverity :: forall a_an12. Lens' (Item a_an12) Severity
+ Katip.Core: itemSeverity :: forall a_an1k. Lens' (Item a_an1k) Severity
- Katip.Core: itemThread :: forall a_an12. Lens' (Item a_an12) ThreadIdText
+ Katip.Core: itemThread :: forall a_an1k. Lens' (Item a_an1k) ThreadIdText
- Katip.Core: itemTime :: forall a_an12. Lens' (Item a_an12) UTCTime
+ Katip.Core: itemTime :: forall a_an1k. Lens' (Item a_an1k) UTCTime
Files
- changelog.md +4/−0
- katip.cabal +1/−1
- src/Katip.hs +1/−0
- src/Katip/Scribes/Handle.hs +16/−2
- test/Katip/Tests/Scribes/Handle.hs +24/−4
changelog.md view
@@ -1,3 +1,7 @@+0.5.1.0+=======+* Add mkFileScribe, a specialization of mkHandleScribe for files that manages the handle automatically.+ 0.5.0.4 ======= * Loosen Win32 upper bound to run with GHC 8.2 on Windows.
katip.cabal view
@@ -1,5 +1,5 @@ name: katip-version: 0.5.0.4+version: 0.5.1.0 synopsis: A structured logging framework. description: Katip is a structured logging framework. See README.md for more details.
src/Katip.hs view
@@ -177,6 +177,7 @@ -- * Included Scribes , mkHandleScribe+ , mkFileScribe , ColorStrategy (..) -- * Tools for implementing Scribes
src/Katip/Scribes/Handle.hs view
@@ -5,7 +5,7 @@ ------------------------------------------------------------------------------- import Control.Applicative as A import Control.Concurrent-import Control.Exception (bracket_)+import Control.Exception (bracket_, finally) import Control.Monad import Data.Aeson import qualified Data.HashMap.Strict as HM@@ -61,7 +61,8 @@ -- > [2016-05-11 21:01:15][MyApp.confrabulation][Debug][myhost.example.com][1724][ThreadId 1154][confrab_factor:42.0][main:Helpers.Logging Helpers/Logging.hs:41:9] Confrabulating widgets, with extra namespace and context -- > [2016-05-11 21:01:15][MyApp][Info][myhost.example.com][1724][ThreadId 1154][main:Helpers.Logging Helpers/Logging.hs:43:7] Namespace and context are back to normal ----- Returns the newly-created `Scribe`. The finalizer flushes the handle.+-- Returns the newly-created `Scribe`. The finalizer flushes the+-- handle. Handle mode is set to 'LineBuffering' automatically. mkHandleScribe :: ColorStrategy -> Handle -> Severity -> Verbosity -> IO Scribe mkHandleScribe cs h sev verb = do hSetBuffering h LineBuffering@@ -73,6 +74,19 @@ when (permitItem sev i) $ bracket_ (takeMVar lock) (putMVar lock ()) $ T.hPutStrLn h $ toLazyText $ formatItem colorize verb i return $ Scribe logger (hFlush h)+++-------------------------------------------------------------------------------+-- | A specialization of 'mkHandleScribe' that takes a 'FilePath'+-- instead of a 'Handle'. It is responsible for opening the file in+-- 'AppendMode' and will close the file handle on+-- 'closeScribe'/'closeScribes'. Does not do log coloring. Sets handle+-- to 'LineBuffering' mode.+mkFileScribe :: FilePath -> Severity -> Verbosity -> IO Scribe+mkFileScribe f sev verb = do+ h <- openFile f AppendMode+ Scribe logger finalizer <- mkHandleScribe (ColorLog False) h sev verb+ return (Scribe logger (finalizer `finally` hClose h)) -------------------------------------------------------------------------------
test/Katip/Tests/Scribes/Handle.hs view
@@ -42,10 +42,19 @@ let pat = "\\[[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}\\]\\[katip-test.test\\]\\[Info\\]\\[.+\\]\\[[[:digit:]]+\\]\\[ThreadId [[:digit:]]+\\]\\[note.deep:some note\\] test message" :: String let matches = res =~ pat assertBool (show res <> " did not match") matches+ , withResource setupFile (const (return ())) $ \setupScribe -> testCase "logs correct data to a file" $ do+ (path, fin, le) <- setupScribe+ runKatipT le $ logItem dummyLogItem "test" Nothing InfoS "test message"+ fin+ runKatipT le $ logItem dummyLogItem "test" Nothing InfoS "wont make it in"+ res <- readFile path+ let pat = "\\[[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}\\]\\[katip-test.test\\]\\[Info\\]\\[.+\\]\\[[[:digit:]]+\\]\\[ThreadId [[:digit:]]+\\]\\[note.deep:some note\\] test message" :: String+ let matches = res =~ pat+ assertBool (show res <> " did not match") matches , withResource setupTempFile teardownTempFile $ \setupFn ->- goldenVsString "Text-golden"- "test/Katip/Tests/Scribes/Handle-text.golden"- (setupFn >>= writeTextLog)+ goldenVsString "Text-golden"+ "test/Katip/Tests/Scribes/Handle-text.golden"+ (setupFn >>= writeTextLog) ] @@ -86,11 +95,22 @@ --------------------------------------------------------------------------------teardown :: (FilePath, Handle, IO (), LogEnv) -> IO ()+teardown :: (a, Handle, b, c) -> IO () teardown (_, h, _, _) = do chk <- hIsOpen h when chk $ hClose h ++-------------------------------------------------------------------------------+setupFile :: IO (FilePath, IO (), LogEnv)+setupFile = do+ tempDir <- getTemporaryDirectory+ (fp, h) <- openTempFile tempDir "katip.log"+ hClose h+ s <- mkFileScribe fp DebugS V3+ le <- initLogEnv "katip-test" "test"+ le' <- registerScribe "handle" s defaultScribeSettings le+ return (fp, void (closeScribes le'), le') -- Following code tests Handle scribe output against a golden file.