@@ -5,6 +5,7 @@
5{-# LANGUAGE RecordWildCards #-}
5{-# LANGUAGE RecordWildCards #-}
6{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE StandaloneDeriving #-}
7{-# LANGUAGE StandaloneDeriving #-}
8+{-# LANGUAGE TemplateHaskell #-}
8{-# OPTIONS_GHC -fno-warn-orphans #-}
9{-# OPTIONS_GHC -fno-warn-orphans #-}
9module Katip.Tests
10module Katip.Tests
@@ -49,6 +50,7 @@ tests = testGroup "Katip"
49 , logContextsTests
50 , logContextsTests
50 , closeScribeTests
51 , closeScribeTests
51 , closeScribesTests
52 , closeScribesTests
@@ -97,6 +99,45 @@ closeScribeTests = testGroup "closeScribe"
102+-------------------------------------------------------------------------------
103+loggingTests :: TestTree
104+loggingTests = testGroup "logging"
105+ [ testCase "logs in order with contexts, namespaces, etc" $ do
106+ (le, items) <- recordingEnv
107+ runKatipContextT le (sl "base_context" (42 :: Int)) "base_namespace" $ do
108+ $(logTM) InfoS "basic log"
110+ $(logTM) InfoS "you cant see this"
111+ katipAddNamespace "added" $ do
112+ katipAddNamespace "namespace" $ do
113+ $(logTM) InfoS "with namespaces"
114+ katipAddContext (sl "additional" True) $ do
115+ $(logTM) InfoS "additional context"
116+ _ <- closeScribes le
117+ summary <- fmap summarizeItem <$> readTVarIO items
118+ let baseCtx = HM.singleton "base_context" (Number 42)
119+ let baseNS = "tests" <> "base_namespace"
121+ [ (baseNS, baseCtx, "basic log")
122+ , (baseNS <> "added" <> "namespace", baseCtx, "with namespaces")
123+ , (baseNS <> "added", HM.insert "additional" (Bool True) baseCtx, "additional context")
127+ recordingEnv :: IO (LogEnv, TVar [Item Object])
129+ items <- newTVarIO mempty
131+ { liPush = \i -> atomically (modifyTVar' items (<> [toObject <$> i]))
132+ , scribeFinalizer = return ()
134+ le1 <- initLogEnv "tests" "test"
135+ le2 <- registerScribe "recorder" scribe defaultScribeSettings le1
137+ summarizeItem :: Item Object -> (Namespace, Object, LogStr)
138+ summarizeItem Item {..} = (_itemNamespace, _itemPayload, _itemMessage)
100-------------------------------------------------------------------------------
141-------------------------------------------------------------------------------
101trivialScribe :: IO (Scribe, TVar Bool)
142trivialScribe :: IO (Scribe, TVar Bool)
102trivialScribe = do
143trivialScribe = do