@@ -32,10 +32,14 @@ import System.Log.FastLogger
32
32
-- ---------------------------------------------------------------------
33
33
34
34
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
36
38
37
39
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
39
43
40
44
-- ---------------------------------------------------------------------
41
45
@@ -49,36 +53,36 @@ instance MonadLogger IO where
49
53
From https://hackage.haskell.org/package/logging-3.0.2/docs/src/Control-Logging.html
50
54
-}
51
55
52
- -- data LogLevel = LevelDebug | LevelInfo | LevelWarn | LevelError | LevelOther Text
53
- -- deriving (Eq, Prelude.Show, Prelude.Read, Ord)
54
-
55
- -- type LogSource = Text
56
56
57
+ -- | Create a new global variable to hold the system-wide log level
57
58
logLevel :: IORef LogLevel
58
59
{-# NOINLINE logLevel #-}
59
60
logLevel = unsafePerformIO $ newIORef LevelDebug
60
61
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'.
63
64
setLogLevel :: LogLevel -> IO ()
64
65
setLogLevel = atomicWriteIORef logLevel
65
66
67
+ -- | Create a new global variable to hold the system-wide log output device
66
68
logSet :: IORef LoggerSet
67
69
{-# NOINLINE logSet #-}
68
70
logSet = unsafePerformIO $
69
71
newIORef (error " Must call withStdoutLogging or withStderrLogging" )
70
72
73
+ -- | Create a new global variable to hold the system-wide log time format
71
74
logTimeFormat :: IORef String
72
75
{-# NOINLINE logTimeFormat #-}
73
76
logTimeFormat = unsafePerformIO $ newIORef " %Y %b-%d %H:%M:%S%Q"
74
77
75
- -- | Set the format used for log timestamps.
78
+ -- | Set the global format used for log timestamps.
76
79
setLogTimeFormat :: String -> IO ()
77
80
setLogTimeFormat = atomicWriteIORef logTimeFormat
78
81
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'.
82
86
withStdoutLogging :: (MonadBaseControl IO m , MonadIO m ) => m a -> m a
83
87
withStdoutLogging f = do
84
88
liftIO $ do
@@ -101,8 +105,8 @@ withFileLogging path f = do
101
105
f `finally` flushLog
102
106
103
107
-- | 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.
106
110
flushLog :: MonadIO m => m ()
107
111
flushLog = liftIO $ do
108
112
set <- readIORef logSet
0 commit comments