Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit f1d17eb

Browse files
committed
Clarify that logging is global, and always flush
1 parent 5896fa6 commit f1d17eb

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/Haskell/Ide/Engine/MonadFunctions.hs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ import System.Log.FastLogger
3232
-- ---------------------------------------------------------------------
3333

3434
logm :: MonadIO m => String -> m ()
35-
logm s = liftIO $ logInfoN $ T.pack s
35+
logm s = do
36+
liftIO (logInfoN $ T.pack s)
37+
flushLog
3638

3739
debugm :: MonadIO m => String -> m ()
38-
debugm s = liftIO $ logDebugN $ T.pack s
40+
debugm s = do
41+
liftIO $ logDebugN $ T.pack s
42+
flushLog
3943

4044
-- ---------------------------------------------------------------------
4145

@@ -49,36 +53,36 @@ instance MonadLogger IO where
4953
From https://hackage.haskell.org/package/logging-3.0.2/docs/src/Control-Logging.html
5054
-}
5155

52-
-- data LogLevel = LevelDebug | LevelInfo | LevelWarn | LevelError | LevelOther Text
53-
-- deriving (Eq, Prelude.Show, Prelude.Read, Ord)
54-
55-
-- type LogSource = Text
5656

57+
-- |Create a new global variable to hold the system-wide log level
5758
logLevel :: IORef LogLevel
5859
{-# NOINLINE logLevel #-}
5960
logLevel = unsafePerformIO $ newIORef LevelDebug
6061

61-
-- | Set the verbosity level. Messages at our higher than this level are
62-
-- displayed. It defaults to 'LevelDebug'.
62+
-- | Set the global verbosity level. Messages at our higher than this level are
63+
-- displayed. It defaults to 'LevelDebug'.
6364
setLogLevel :: LogLevel -> IO ()
6465
setLogLevel = atomicWriteIORef logLevel
6566

67+
-- |Create a new global variable to hold the system-wide log output device
6668
logSet :: IORef LoggerSet
6769
{-# NOINLINE logSet #-}
6870
logSet = unsafePerformIO $
6971
newIORef (error "Must call withStdoutLogging or withStderrLogging")
7072

73+
-- |Create a new global variable to hold the system-wide log time format
7174
logTimeFormat :: IORef String
7275
{-# NOINLINE logTimeFormat #-}
7376
logTimeFormat = unsafePerformIO $ newIORef "%Y %b-%d %H:%M:%S%Q"
7477

75-
-- | Set the format used for log timestamps.
78+
-- | Set the global format used for log timestamps.
7679
setLogTimeFormat :: String -> IO ()
7780
setLogTimeFormat = atomicWriteIORef logTimeFormat
7881

79-
-- | This function, or 'withStderrLogging', must be wrapped around whatever
80-
-- region of your application intends to use logging. Typically it would be
81-
-- wrapped around the body of 'main'.
82+
-- | This function, or 'withStderrLogging' or 'withFileLogging', must be wrapped
83+
-- around whatever region of your application will be alive for the duration
84+
-- that logging will be used. Typically it would be wrapped around the body of
85+
-- 'main'.
8286
withStdoutLogging :: (MonadBaseControl IO m, MonadIO m) => m a -> m a
8387
withStdoutLogging f = do
8488
liftIO $ do
@@ -101,8 +105,8 @@ withFileLogging path f = do
101105
f `finally` flushLog
102106

103107
-- | Flush all collected logging messages. This is automatically called by
104-
-- 'withStdoutLogging' and 'withStderrLogging' when those blocks are exited
105-
-- by whatever means.
108+
-- 'withStdoutLogging', 'withStderrLogging' and 'withFileLogging' when those
109+
-- blocks are exited by whatever means.
106110
flushLog :: MonadIO m => m ()
107111
flushLog = liftIO $ do
108112
set <- readIORef logSet

0 commit comments

Comments
 (0)