Skip to content

Commit 28ea9cf

Browse files
committed
rename all logging utilities
1 parent 9bb10be commit 28ea9cf

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

Web/SocketIO/Connection.hs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ lookupSession :: SessionID -> ConnectionM (Maybe Session)
5454
lookupSession sessionID = do
5555
tableRef <- getSessionTableRef
5656
table <- liftIO (readIORef tableRef)
57-
--debug Debug $ sessionID <> " [Session] Lookup"
5857
return (H.lookup sessionID table)
5958

6059
--------------------------------------------------------------------------------
@@ -99,8 +98,8 @@ handleConnection (Handshake, _) = do
9998

10099
-- session table management
101100
updateSession (H.insert sessionID session)
102-
debugLog Debug session "[Session] Created"
103-
debugLog Debug session "[Request] Handshake"
101+
logWithSessionID Debug sessionID "[Session] Created"
102+
logWithSessionID Debug sessionID "[Request] Handshake"
104103

105104
-- timeout
106105
setTimeout session
@@ -121,45 +120,45 @@ handleConnection (Handshake, _) = do
121120
return $ Session sessionID Connecting channelHub listeners timeoutVar
122121

123122
handleConnection (Connect sessionID, Just (session, Connecting)) = do
124-
debugLog Debug session "[Request] Connect: ACK"
123+
logWithSessionID Debug sessionID "[Request] Connect: ACK"
125124
extendTimeout session
126125
let session' = session { sessionState = Connected }
127126
updateSession (H.insert sessionID session')
128127
runSession SessionConnect session'
129128

130-
handleConnection (Connect _, Just (session, Connected)) = do
131-
debugLog Debug session "[Request] Connect: Polling"
129+
handleConnection (Connect sessionID, Just (session, Connected)) = do
130+
logWithSessionID Debug sessionID "[Request] Connect: Polling"
132131
extendTimeout session
133132
runSession SessionPolling session
134133

135134
handleConnection (Connect sessionID, Nothing) = do
136-
debug Warn $ sessionID <> " [Request] Connect: Session not found"
135+
logWithSessionID Warn sessionID "[Request] Connect: Session not found"
137136
return $ MsgError NoEndpoint NoData
138137

139138
handleConnection (Disconnect sessionID, Just (session, _)) = do
140-
debugLog Debug session "[Request] Disconnect: By client"
139+
logWithSessionID Debug sessionID "[Request] Disconnect: By client"
141140
clearTimeout session
142141
updateSession (H.delete sessionID)
143-
debugLog Debug session "[Session] Destroyed"
142+
logWithSessionID Debug sessionID "[Session] Destroyed"
144143
runSession SessionDisconnectByClient session
145144

146145
handleConnection (Disconnect sessionID, Nothing) = do
147-
debug Warn $ sessionID <> " [Request] Disconnect: Session not found"
146+
logWithSessionID Warn sessionID "[Request] Disconnect: Session not found"
148147
return MsgNoop
149148

150-
handleConnection (Emit _ _, Just (session, Connecting)) = do
149+
handleConnection (Emit sessionID _, Just (session, Connecting)) = do
151150
extendTimeout session
152-
debugLog Warn session "[Request] Emit: Session still connecting, not ACKed"
151+
logWithSessionID Warn sessionID "[Request] Emit: Session still connecting, not ACKed"
153152
return $ MsgError NoEndpoint NoData
154153

155-
handleConnection (Emit _ event@(Event eventName (Payload payloads)), Just (session, Connected)) = do
156-
debugLog Debug session $ "[Request] Emit: " <> serialize eventName <> " " <> serialize payloads
154+
handleConnection (Emit sessionID event@(Event eventName (Payload payloads)), Just (session, Connected)) = do
155+
logWithSessionID Debug sessionID $ "[Request] Emit: " <> serialize eventName <> " " <> serialize payloads
157156
runSession (SessionEmit event) session
158157

159-
handleConnection (Emit _ NoEvent, Just (session, Connected)) = do
160-
debugLog Warn session $ "[Request] Emit: event malformed"
158+
handleConnection (Emit sessionID NoEvent, Just (_, Connected)) = do
159+
logWithSessionID Warn sessionID "[Request] Emit: event malformed"
161160
return $ MsgError NoEndpoint NoData
162161

163162
handleConnection (Emit sessionID _, Nothing) = do
164-
debug Warn $ sessionID <> " [Request] Emit: Session not found"
163+
logWithSessionID Warn sessionID "[Request] Emit: Session not found"
165164
return $ MsgError NoEndpoint NoData

Web/SocketIO/Log.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- | Exports some logging utilities.
33
{-# LANGUAGE OverloadedStrings #-}
44

5-
module Web.SocketIO.Log ((<>), debugLog, debugSession, debug, showStatusBar) where
5+
module Web.SocketIO.Log ((<>), logRaw, logWithSession, logWithSessionID, showStatusBar) where
66

77
--------------------------------------------------------------------------------
88
import Web.SocketIO.Types
@@ -13,8 +13,8 @@ import Control.Monad.Trans (liftIO, MonadIO)
1313

1414
--------------------------------------------------------------------------------
1515
-- | Write log to channel according to log level and configurations
16-
debug :: (Functor m, MonadIO m, ConnectionLayer m) => (ByteString -> Log) -> ByteString -> m ()
17-
debug logType message = do
16+
logRaw :: (Functor m, MonadIO m, ConnectionLayer m) => (ByteString -> Log) -> ByteString -> m ()
17+
logRaw logType message = do
1818
logLevel' <- fmap logLevel getConfiguration
1919
logChannel <- fmap envLogChannel getEnv
2020
if level <= logLevel' then liftIO $ writeChan logChannel (serialize log') else return ()
@@ -27,15 +27,15 @@ debug logType message = do
2727

2828
--------------------------------------------------------------------------------
2929
-- | Attaches `Web.SocketIO.Types.Base.SessionID`
30-
debugLog :: (Functor m, MonadIO m, ConnectionLayer m) => (ByteString -> Log) -> Session -> ByteString -> m ()
31-
debugLog logType (Session sessionID _ _ _ _) message = debug logType (sessionID <> " " <> serialize message)
30+
logWithSessionID :: (Functor m, MonadIO m, ConnectionLayer m) => (ByteString -> Log) -> SessionID -> ByteString -> m ()
31+
logWithSessionID logType sessionID message = logRaw logType (sessionID <> " " <> serialize message)
3232

3333
--------------------------------------------------------------------------------
3434
-- | Attaches `Web.SocketIO.Types.Base.SessionID` automatically
35-
debugSession :: (Functor m, MonadIO m, ConnectionLayer m, SessionLayer m) => (ByteString -> Log) -> ByteString -> m ()
36-
debugSession logType message = do
35+
logWithSession :: (Functor m, MonadIO m, ConnectionLayer m, SessionLayer m) => (ByteString -> Log) -> ByteString -> m ()
36+
logWithSession logType message = do
3737
Session sessionID _ _ _ _ <- getSession
38-
debug logType $ fromByteString (sessionID <> " " <> message)
38+
logRaw logType $ fromByteString (sessionID <> " " <> message)
3939

4040
--------------------------------------------------------------------------------
4141
-- | Show status bar

Web/SocketIO/Session.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ handleSession SessionHandshake = do
3333

3434

3535
handleSession SessionConnect = do
36-
debugSession Info $ "Connected"
36+
logWithSession Info $ "Connected"
3737
return $ MsgConnect NoEndpoint
3838

3939
handleSession SessionPolling = do
@@ -45,35 +45,35 @@ handleSession SessionPolling = do
4545
case result of
4646
-- private
4747
Just (Private, Event eventName payloads) -> do
48-
debugSession Info $ "Emit: " <> serialize eventName
48+
logWithSession Info $ "Emit: " <> serialize eventName
4949
return $ MsgEvent NoID NoEndpoint (Event eventName payloads)
5050
-- broadcast
5151
Just (Broadcast _, Event eventName payloads) -> do
5252
-- this log will cause massive overhead, need to be removed
53-
debugSession Info $ "Broadcast: " <> serialize eventName
53+
logWithSession Info $ "Broadcast: " <> serialize eventName
5454
return $ MsgEvent NoID NoEndpoint (Event eventName payloads)
5555
-- wtf
5656
Just (_, NoEvent) -> do
57-
debugSession Error $ "Event malformed"
57+
logWithSession Error $ "Event malformed"
5858
return $ MsgEvent NoID NoEndpoint NoEvent
5959
-- no output, keep polling
6060
Nothing -> do
6161
return MsgNoop
6262

6363
handleSession (SessionEmit event) = do
6464
case event of
65-
Event eventName _ -> debugSession Info $ "On: " <> serialize eventName
66-
NoEvent -> debugSession Error $ "Event malformed"
65+
Event eventName _ -> logWithSession Info $ "On: " <> serialize eventName
66+
NoEvent -> logWithSession Error $ "Event malformed"
6767
triggerEvent event
6868
return $ MsgConnect NoEndpoint
6969

7070
handleSession SessionDisconnectByClient = do
71-
debugSession Info $ "Disconnected by client"
71+
logWithSession Info $ "Disconnected by client"
7272
triggerEvent (Event "disconnect" (Payload []))
7373
return $ MsgNoop
7474

7575
handleSession SessionDisconnectByServer = do
76-
debugSession Info $ "Disconnected by server"
76+
logWithSession Info $ "Disconnected by server"
7777
triggerEvent (Event "disconnect" (Payload []))
7878
return $ MsgNoop
7979

Web/SocketIO/Timeout.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ primTimeout' firstTime session@(Session sessionID _ _ _ timeoutVar) = do
3737
duration <- getTimeoutDuration
3838

3939
if firstTime
40-
then debug Debug $ sessionID <> " [Session] Set timeout"
41-
else debug Debug $ sessionID <> " [Session] Extend timeout"
40+
then logWithSessionID Debug sessionID "[Session] Set timeout"
41+
else logWithSessionID Debug sessionID "[Session] Extend timeout"
4242
result <- timeout duration $ takeMVar timeoutVar
4343

4444
case result of
@@ -51,7 +51,7 @@ primTimeout' firstTime session@(Session sessionID _ _ _ timeoutVar) = do
5151
-- remove session
5252
tableRef <- getSessionTableRef
5353
liftIO (modifyIORef tableRef (H.delete sessionID))
54-
debug Debug $ sessionID <> " [Session] Destroyed: close timeout"
54+
logWithSessionID Debug sessionID "[Session] Destroyed: close timeout"
5555

5656
----------------------------------------------------------------------------------
5757
-- | Set timeout

0 commit comments

Comments
 (0)