@@ -143,34 +143,34 @@ showLS = ls . show
143143-------------------------------------------------------------------------------
144144-- | This has everything each log message will contain.
145145data Item a = Item {
146− itemApp :: Namespace
147− , itemEnv :: Environment
148− , itemSeverity :: Severity
149− , itemThread :: ThreadId
150− , itemHost :: HostName
151− , itemProcess :: ProcessID
152− , itemPayload :: a
153− , itemMessage :: LogStr
154− , itemTime :: UTCTime
155− , itemNamespace :: Namespace
156− , itemLoc :: Maybe Loc
146+ _itemApp :: Namespace
147+ , _itemEnv :: Environment
148+ , _itemSeverity :: Severity
149+ , _itemThread :: ThreadId
150+ , _itemHost :: HostName
151+ , _itemProcess :: ProcessID
152+ , _itemPayload :: a
153+ , _itemMessage :: LogStr
154+ , _itemTime :: UTCTime
155+ , _itemNamespace :: Namespace
156+ , _itemLoc :: Maybe Loc
157157 } deriving (Generic)
158−
158+makeLenses ''Item
159159
160160
161161instance ToJSON a => ToJSON (Item a) where
162162 toJSON Item{..} = A.object
163− [ "app" A..= itemApp
164− , "env" A..= itemEnv
165− , "sev" A..= itemSeverity
166− , "thread" A..= show itemThread
167− , "host" A..= itemHost
168− , "pid" A..= A.String (toS (show itemProcess))
169− , "data" A..= itemPayload
170− , "msg" A..= (B.toLazyText $ unLogStr itemMessage)
171− , "at" A..= itemTime
172− , "ns" A..= itemNamespace
173− , "loc" A..= fmap LocJs itemLoc
163+ [ "app" A..= _itemApp
164+ , "env" A..= _itemEnv
165+ , "sev" A..= _itemSeverity
166+ , "thread" A..= show _itemThread
167+ , "host" A..= _itemHost
168+ , "pid" A..= A.String (toS (show _itemProcess))
169+ , "data" A..= _itemPayload
170+ , "msg" A..= (B.toLazyText $ unLogStr _itemMessage)
171+ , "at" A..= _itemTime
172+ , "ns" A..= _itemNamespace
173+ , "loc" A..= fmap LocJs _itemLoc
174174 ]
175175
176176newtype LocJs = LocJs { getLocJs :: Loc }
@@ -224,6 +224,14 @@ payloadJson verb a = case foldMap (flip payloadKeys a) [(V0)..verb] of
224224 & _Object %~ HM.filterWithKey (\ k _ -> k `elem` ks)
225225
226226
227+-------------------------------------------------------------------------------
228+-- | Convert log item to its JSON representation while trimming its
229+-- payload based on the desired verbosity. Backends that push JSON
230+-- messages should use this to obtain their payload.
231+itemJson :: LogContext a => Verbosity -> Item a -> A.Value
232+itemJson verb a = toJSON $ a & itemPayload %~ payloadJson verb
233+
234+
227235-------------------------------------------------------------------------------
228236-- | Scribes are handlers of incoming items. Each registered scribe
229237-- knows how to push a log item somewhere.