packages feed

logging 1.2.0 → 1.3.0

raw patch · 3 files changed

+24/−16 lines, 3 files

Files

Control/Logging.hs view
@@ -52,11 +52,12 @@     , timedDebugEndS'     , withStdoutLogging     , withStderrLogging+    , withFileLogging     , flushLog     , loggingLogger-    , setDebugLevel-    , setLogFormat-    , setDebugSourceRegexp+    , setLogLevel+    , setLogTimeFormat+    , setDebugSourceRegex     ) where  import Control.Exception.Lifted@@ -84,21 +85,21 @@  -- | Set the verbosity level.  Messages at our higher than this level are --   displayed.  It defaults to 'LevelDebug'.-setDebugLevel :: LogLevel -> IO ()-setDebugLevel = atomicWriteIORef logLevel+setLogLevel :: LogLevel -> IO ()+setLogLevel = atomicWriteIORef logLevel  logSet :: IORef LoggerSet {-# NOINLINE logSet #-} logSet = unsafePerformIO $     newIORef (error "Must call withStdoutLogging or withStderrLogging") -logFormat :: IORef String-{-# NOINLINE logFormat #-}-logFormat = unsafePerformIO $ newIORef "%Y %b-%d %H:%M:%S%Q"+logTimeFormat :: IORef String+{-# NOINLINE logTimeFormat #-}+logTimeFormat = unsafePerformIO $ newIORef "%Y %b-%d %H:%M:%S%Q"  -- | Set the format used for log timestamps.-setLogFormat :: String -> IO ()-setLogFormat = atomicWriteIORef logFormat+setLogTimeFormat :: String -> IO ()+setLogTimeFormat = atomicWriteIORef logTimeFormat  debugSourceRegexp :: IORef (Maybe Regex) {-# NOINLINE debugSourceRegexp #-}@@ -107,8 +108,8 @@ -- | When printing 'LevelDebug' messages, only display those matching the --   given regexp applied to the Source parameter.  Calls to 'debug' without a --   source parameter are regarded as having a source of @""@.-setDebugSourceRegexp :: String -> IO ()-setDebugSourceRegexp =+setDebugSourceRegex :: String -> IO ()+setDebugSourceRegex =     atomicWriteIORef debugSourceRegexp         . Just         . flip compile []@@ -129,7 +130,7 @@                 Just re -> isJust (match re (encodeUtf8 src) [])         when willLog $ do             now <- getCurrentTime-            fmt <- readIORef logFormat+            fmt <- readIORef logTimeFormat             let stamp = formatTime defaultTimeLocale fmt now             set <- readIORef logSet             pushLogStr set@@ -163,6 +164,13 @@ withStderrLogging f = do     liftIO $ do         set <- newStderrLoggerSet defaultBufSize+        atomicWriteIORef logSet set+    f `finally` flushLog++withFileLogging :: (MonadBaseControl IO m, MonadIO m) => FilePath -> m a -> m a+withFileLogging path f = do+    liftIO $ do+        set <- newFileLoggerSet defaultBufSize path         atomicWriteIORef logSet set     f `finally` flushLog 
logging.cabal view
@@ -1,5 +1,5 @@ Name:                logging-Version:             1.2.0+Version:             1.3.0 Synopsis:            Simplified logging in IO for application writers. License-file:        LICENSE License:             MIT
test/main.hs view
@@ -22,11 +22,11 @@             return ()          it "can be passed to runLoggingT" $ do-            flip runLoggingT loggingLogger $ (log "Hello" :: LoggingT IO ())+            flip runLoggingT loggingLogger (log "Hello" :: LoggingT IO ())             flushLog          it "supports using debug classes" $ do-            setDebugSourceRegexp "foo\\..*"+            setDebugSourceRegex "foo\\..*"             withStdoutLogging $ do                 debugS "foo" "This is a foo message"                 debugS "foo.bar" "This is a foo.bar message"