Skip to content

Commit 0c3e06a

Browse files
committed
Generalize log functions to MonadIO.
1 parent eef0354 commit 0c3e06a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

co-log-json/src/Colog/Json.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module Colog.Json
6565
import Colog.Core hiding (Severity)
6666
import Colog.Json.Internal.Structured
6767
import Control.Concurrent
68+
import Control.Monad.IO.Class
6869
import Data.Sequence qualified as Seq
6970
import Data.Text qualified as T
7071

@@ -170,7 +171,7 @@ addNamespace ns LoggerEnv{..} = LoggerEnv{context=context Seq.|> Segment ns, ..}
170171

171172
logDebug, logNotice, logInfo, logWarn,
172173
logErr, logAlert, logCrit, logEmergency
173-
:: LoggerEnv -> LogStr -> IO ()
174+
:: MonadIO m => LoggerEnv -> LogStr -> m ()
174175
logDebug x = logSay x DebugS
175176
logNotice x = logSay x InfoS
176177
logInfo x = logSay x InfoS
@@ -181,10 +182,12 @@ logAlert x = logSay x AlertS
181182
logEmergency x = logSay x EmergencyS
182183

183184
-- | Internal logger function.
184-
logSay :: LoggerEnv -- ^ Logger handle.
185+
logSay :: MonadIO m
186+
=> LoggerEnv -- ^ Logger handle.
185187
-> Severity -- ^ Message severity.
186188
-> LogStr -- ^ Message itself.
187-
-> IO ()
188-
logSay (LoggerEnv action context) lvl msg = do
189+
-> m ()
190+
logSay (LoggerEnv action context) lvl msg = liftIO $ do
189191
tid <- myThreadId
190192
unLogAction action $ Message lvl (mkThreadId tid) context msg
193+
{-# SPECIALIZE logSay :: LoggerEnv -> Severity -> LogStr -> IO () #-}

0 commit comments

Comments
 (0)