@@ -223,6 +223,7 @@ stickyLoggerFunc loc src level msg = do
223223 case mref of
224224 Nothing ->
225225 loggerFunc
226+ out
226227 loc
227228 src
228229 (case level of
@@ -239,7 +240,7 @@ stickyLoggerFunc loc src level msg = do
239240 (maybe 0 T. length sticky)
240241 clear =
241242 liftIO
242- (S8. putStr
243+ (S8. hPutStr out
243244 (repeating backSpaceChar <>
244245 repeating ' ' <>
245246 repeating backSpaceChar))
@@ -255,26 +256,27 @@ stickyLoggerFunc loc src level msg = do
255256 case level of
256257 LevelOther " sticky-done" -> do
257258 clear
258- liftIO (T. putStrLn msgText)
259+ liftIO (T. hPutStrLn out msgText)
259260 return Nothing
260261 LevelOther " sticky" -> do
261262 clear
262- liftIO (T. putStr msgText)
263+ liftIO (T. hPutStr out msgText)
263264 return (Just msgText)
264265 _
265266 | level >= maxLogLevel -> do
266267 clear
267- loggerFunc loc src level $ toLogStr msgText
268+ loggerFunc out loc src level $ toLogStr msgText
268269 case sticky of
269270 Nothing ->
270271 return Nothing
271272 Just line -> do
272- liftIO (T. putStr line)
273+ liftIO (T. hPutStr out line)
273274 return sticky
274275 | otherwise ->
275276 return sticky
276277 liftIO (putMVar ref newState)
277278 where
279+ out = stderr
278280 msgTextRaw = T. decodeUtf8With T. lenientDecode msgBytes
279281 msgBytes = fromLogStr (toLogStr msg)
280282
@@ -286,14 +288,13 @@ replaceUnicode c = c
286288
287289-- | Logging function takes the log level into account.
288290loggerFunc :: (MonadIO m ,ToLogStr msg ,MonadReader r m ,HasLogLevel r )
289- => Loc -> Text -> LogLevel -> msg -> m ()
290- loggerFunc loc _src level msg =
291+ => Handle -> Loc -> Text -> LogLevel -> msg -> m ()
292+ loggerFunc outputChannel loc _src level msg =
291293 do maxLogLevel <- asks getLogLevel
292294 when (level >= maxLogLevel)
293295 (liftIO (do out <- getOutput maxLogLevel
294296 T. hPutStrLn outputChannel out))
295- where outputChannel = stderr
296- getOutput maxLogLevel =
297+ where getOutput maxLogLevel =
297298 do timestamp <- getTimestamp
298299 l <- getLevel
299300 lc <- getLoc
0 commit comments