Skip to content

Commit e143462

Browse files
committed
Add LogSource to logging calls
commit 0044eec098a25bb1f585555376b3a124f1cbede6 Author: Jean-Pierre Rupp <[email protected]> Date: Fri Jun 19 14:36:07 2020 +0100 Prepare release commit e695e00 Author: Javran Cheng <[email protected]> Date: Mon Jun 15 22:39:51 2020 -0700 Add LogSource to library's logging calls. This patch replaces many `logXXX`s with `logXXXS "json-rpc"`s so that user can filter logs based on LogSource. Fixes #9.
1 parent 5babcc0 commit e143462

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## 1.0.2 - 2019-06-12
7+
## 1.0.3 - 2020-06-19
8+
9+
### Changed
10+
- `LogSource` (defined in `monad-logger`) for this library is set to `"json-rpc"` so that logs can be filtered base on it.
11+
12+
## 1.0.2 - 2020-06-12
813
### Changed
914
- Change license to MIT.
1015

json-rpc.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: fa906567c9820e7b3dd72def851fbe59bf79196757efa257ad6d5a97280a3ec2
7+
-- hash: 77cd2980380a86ce6731e9afcae7c2ecc42257843e71231bcebaba6929bee5c8
88

99
name: json-rpc
10-
version: 1.0.2
10+
version: 1.0.3
1111
synopsis: Fully-featured JSON-RPC 2.0 library
12-
description: Library compatible with JSON-RPC 2.0 and 1.0
12+
description: Please see the README on GitHub at <https://github.com/jprupp/json-rpc#readme>
1313
category: Network
1414
homepage: https://github.com/jprupp/json-rpc.git#readme
1515
bug-reports: https://github.com/jprupp/json-rpc.git/issues

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json-rpc
2-
version: 1.0.2
2+
version: 1.0.3
33
synopsis: Fully-featured JSON-RPC 2.0 library
44
description: Please see the README on GitHub at <https://github.com/jprupp/json-rpc#readme>
55
category: Network

src/Network/JSONRPC/Interface.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ decodeConduit ver = evalStateT loop Nothing where
9898
runParser ck = maybe (parse json ck) ($ ck) <$> get <* put Nothing
9999

100100
handl True (Fail "" _ _) =
101-
$(logDebug) "ignoring null string at end of incoming data"
101+
$logDebugS "json-rpc" "ignoring null string at end of incoming data"
102102
handl b (Fail i _ _) = do
103-
$(logError) "error parsing incoming message"
103+
$logErrorS "json-rpc" "error parsing incoming message"
104104
lift . yield . Left $ OrphanError ver (errorParse i)
105105
unless b loop
106106
handl _ (Partial k) = put (Just k) >> loop
@@ -123,7 +123,7 @@ processIncoming =
123123
Right v@Object {} -> do
124124
single qs v
125125
return $ do
126-
$(logDebug) "received message"
126+
$logDebugS "json-rpc" "received message"
127127
processIncoming
128128
Right v@(Array a) -> do
129129
if V.null a
@@ -132,18 +132,18 @@ processIncoming =
132132
writeTBMChan (outCh qs) $ MsgResponse e
133133
else batch qs (V.toList a)
134134
return $ do
135-
$(logDebug) "received batch"
135+
$logDebugS "json-rpc" "received batch"
136136
processIncoming
137137
Right v -> do
138138
let e = OrphanError (rpcVer qs) (errorInvalid v)
139139
writeTBMChan (outCh qs) $ MsgResponse e
140140
return $ do
141-
$(logWarn) "got invalid message"
141+
$logWarnS "json-rpc" "got invalid message"
142142
processIncoming
143143
Left e -> do
144144
writeTBMChan (outCh qs) $ MsgResponse e
145145
return $ do
146-
$(logWarn) "error parsing JSON"
146+
$logWarnS "json-rpc" "error parsing JSON"
147147
processIncoming
148148
where
149149
flush qs = do
@@ -153,8 +153,8 @@ processIncoming =
153153
writeTVar (dead qs) True
154154
mapM_ ((`putTMVar` Nothing) . snd) $ M.toList m
155155
return $ do
156-
$(logDebug) "session is now dead"
157-
unless (M.null m) $ $(logError) "requests remained unfulfilled"
156+
$logDebugS "json-rpc" "session is now dead"
157+
unless (M.null m) $ $logErrorS "json-rpc" "requests remained unfulfilled"
158158
batch qs vs = do
159159
ts <- catMaybes <$> forM vs (process qs)
160160
unless (null ts) $
@@ -247,8 +247,8 @@ sendBatchRequest qs = do
247247
as -> unless d $ writeTBMChan o $ MsgBatch $ map MsgRequest as
248248
return aps
249249
if null aps
250-
then $(logDebug) "no responses pending"
251-
else $(logDebug) "listening for responses if pending"
250+
then $logDebugS "json-rpc" "no responses pending"
251+
else $logDebugS "json-rpc" "listening for responses if pending"
252252
liftIO . atomically $ forM aps $ \(a, pM) ->
253253
case pM of
254254
Nothing -> return Nothing
@@ -284,10 +284,10 @@ receiveBatchRequest = do
284284
chM <- reader reqCh
285285
case chM of
286286
Just ch -> do
287-
$(logDebug) "listening for a new request"
287+
$logDebugS "json-rpc" "listening for a new request"
288288
liftIO . atomically $ readTBMChan ch
289289
Nothing -> do
290-
$(logError) "ignoring requests from remote endpoint"
290+
$logErrorS "json-rpc" "ignoring requests from remote endpoint"
291291
return Nothing
292292

293293
-- | Send response message. Do not use to respond to a batch of requests.

0 commit comments

Comments
 (0)