on master help sign in
Add show instance for Item for easier use in GHCi
2c7a57eMichael Xavier
katip/src/Katip/Core.hs+27−2
@@ -8,7 +8,6 @@
8{-# LANGUAGE RankNTypes #-}
8{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE RecordWildCards #-}
9{-# LANGUAGE RecordWildCards #-}
10{-# LANGUAGE TemplateHaskell #-}
10{-# LANGUAGE TemplateHaskell #-}
11−
12module Katip.Core where
11module Katip.Core where
13
12
14-------------------------------------------------------------------------------
13-------------------------------------------------------------------------------
@@ -143,7 +142,7 @@ instance FromJSON Severity where
143-------------------------------------------------------------------------------
142-------------------------------------------------------------------------------
144-- | Log message with Builder unerneath; use '<>' to concat in O(1).
143-- | Log message with Builder unerneath; use '<>' to concat in O(1).
145newtype LogStr = LogStr { unLogStr :: B.Builder }
144newtype LogStr = LogStr { unLogStr :: B.Builder }
146− deriving (Generic)
145+ deriving (Generic, Show)
147
146
148instance IsString LogStr where
147instance IsString LogStr where
149 fromString = LogStr . B.fromString
148 fromString = LogStr . B.fromString
@@ -203,6 +202,32 @@ data Item a = Item {
203makeLenses ''Item
202makeLenses ''Item
204
203
205
204
205+instance Show a => Show (Item a) where
206+ show Item{..} = "Item {_itemApp = " ++ show _itemApp ++ ", " ++
207+ "_itemEnv = " ++ show _itemEnv ++ ", " ++
208+ "_itemSeverity = " ++ show _itemSeverity ++ ", " ++
209+ "_itemThread = " ++ show _itemThread ++ ", " ++
210+ "_itemHost = " ++ show _itemHost ++ ", " ++
211+ "_itemProcess = " ++ show _itemProcess ++ ", " ++
212+ "_itemPayload = " ++ show _itemPayload ++ ", " ++
213+ "_itemMessage = " ++ show _itemMessage ++ ", " ++
214+ "_itemTime = " ++ show _itemTime ++ ", " ++
215+ "_itemNamespace = " ++ show _itemNamespace ++ ", " ++
216+ "_itemLoc = " ++ show (LocShow <$> _itemLoc) ++ "}"
217+
218+
219+newtype LocShow = LocShow Loc
220+
221+
222+instance Show LocShow where
223+ show (LocShow Loc{..}) =
224+ "Loc {loc_filename = " ++ show loc_filename ++ ", " ++
225+ "loc_package = " ++ show loc_package ++ ", " ++
226+ "loc_module = " ++ show loc_module ++ ", " ++
227+ "loc_start = " ++ show loc_start ++ ", " ++
228+ "loc_end = " ++ show loc_end ++ "}"
229+
230+
206instance ToJSON a => ToJSON (Item a) where
231instance ToJSON a => ToJSON (Item a) where
207 toJSON Item{..} = A.object
232 toJSON Item{..} = A.object
208 [ "app" A..= _itemApp
233 [ "app" A..= _itemApp
katip/test/Katip/Tests.hs−3
@@ -71,10 +71,7 @@ deriving instance Arbitrary ThreadIdText
71deriving instance Arbitrary CPid
71deriving instance Arbitrary CPid
72deriving instance Eq Loc
72deriving instance Eq Loc
73deriving instance Eq LogStr
73deriving instance Eq LogStr
74−deriving instance Show Loc
75−deriving instance Show LogStr
76deriving instance (Eq a) => Eq (Item a)
74deriving instance (Eq a) => Eq (Item a)
77−deriving instance (Show a) => Show (Item a)
78
75
79
76
80-------------------------------------------------------------------------------
77-------------------------------------------------------------------------------