on master help sign in
Add show instance for Item for easier use in GHCi
commit2c7a57e4fd40d01e13ca6de1adb916e114f6cc2f authorMichael Xavier <michael@michaelxavier.net> dateFri 8 May 2015, 09:17 (11 years ago) parent744414a
2 files changed+27−5
katip/src/Katip/Core.hs+27−2 katip/test/Katip/Tests.hs−3
katip/src/Katip/Core.hs+27−2
@@ -8,7 +8,6 @@
88{-# LANGUAGE RankNTypes #-}
99{-# LANGUAGE RecordWildCards #-}
1010{-# LANGUAGE TemplateHaskell #-}
11−
1211module Katip.Core where
1312
1413-------------------------------------------------------------------------------
@@ -143,7 +142,7 @@ instance FromJSON Severity where
143142-------------------------------------------------------------------------------
144143-- | Log message with Builder unerneath; use '<>' to concat in O(1).
145144newtype LogStr = LogStr { unLogStr :: B.Builder }
146− deriving (Generic)
145+ deriving (Generic, Show)
147146
148147instance IsString LogStr where
149148 fromString = LogStr . B.fromString
@@ -203,6 +202,32 @@ data Item a = Item {
203202makeLenses ''Item
204203
205204
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+
206231instance ToJSON a => ToJSON (Item a) where
207232 toJSON Item{..} = A.object
208233 [ "app" A..= _itemApp
katip/test/Katip/Tests.hs−3
@@ -71,10 +71,7 @@ deriving instance Arbitrary ThreadIdText
7171deriving instance Arbitrary CPid
7272deriving instance Eq Loc
7373deriving instance Eq LogStr
74−deriving instance Show Loc
75−deriving instance Show LogStr
7674deriving instance (Eq a) => Eq (Item a)
77−deriving instance (Show a) => Show (Item a)
7875
7976
8077-------------------------------------------------------------------------------