logging 1.4.1 → 2.1.0
raw patch · 2 files changed
+49/−4 lines, 2 filesdep ~fast-loggerdep ~monad-logger
Dependency ranges changed: fast-logger, monad-logger
Files
- Control/Logging.hs +46/−1
- logging.cabal +3/−3
Control/Logging.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE RankNTypes #-}+ {-# OPTIONS_GHC -Wall -fno-warn-orphans #-} -- | Quick example of how to use this module:@@ -51,9 +53,13 @@ , timedDebugEndS , timedDebugEndS' , withStdoutLogging+ , withStdoutLoggingUsing , withStderrLogging+ , withStderrLoggingUsing , withFileLogging+ , withFileLoggingUsing , flushLog+ , LoggingLogger , loggingLogger , setLogLevel , setLogTimeFormat@@ -116,6 +122,9 @@ . encodeUtf8 . T.pack +newtype LoggingLogger = LoggingLogger+ { getLoggingLogger :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> IO () }+ -- | This function is used to implement 'monadLoggerLog' for the IO instance. -- You may reuse it if you wish, or it can be passed as an argument to -- 'runLoggingT' -- in which case you must remember to call 'flushLog'@@ -150,30 +159,64 @@ renderLevel LevelError = "[ERROR]" renderLevel (LevelOther txt) = "[" ++ unpack txt ++ "]" +logFunction :: IORef LoggingLogger+{-# NOINLINE logFunction #-}+logFunction = unsafePerformIO $ newIORef (LoggingLogger loggingLogger)+ -- | This function, or 'withStderrLogging', must be wrapped around whatever -- region of your application intends to use logging. Typically it would be -- wrapped around the body of 'main'. withStdoutLogging :: (MonadBaseControl IO m, MonadIO m) => m a -> m a withStdoutLogging f = do liftIO $ do+ writeIORef logFunction (LoggingLogger loggingLogger) set <- newStdoutLoggerSet defaultBufSize atomicWriteIORef logSet set f `finally` flushLog +withStdoutLoggingUsing :: (MonadBaseControl IO m, MonadIO m)+ => LoggingLogger -> m a -> m a+withStdoutLoggingUsing logf f = do+ liftIO $ do+ writeIORef logFunction logf+ set <- newStdoutLoggerSet defaultBufSize+ atomicWriteIORef logSet set+ f `finally` flushLog+ withStderrLogging :: (MonadBaseControl IO m, MonadIO m) => m a -> m a withStderrLogging f = do liftIO $ do+ writeIORef logFunction (LoggingLogger loggingLogger) set <- newStderrLoggerSet defaultBufSize atomicWriteIORef logSet set f `finally` flushLog +withStderrLoggingUsing :: (MonadBaseControl IO m, MonadIO m)+ => LoggingLogger -> m a -> m a+withStderrLoggingUsing logf f = do+ liftIO $ do+ writeIORef logFunction logf+ 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+ writeIORef logFunction (LoggingLogger loggingLogger) set <- newFileLoggerSet defaultBufSize path atomicWriteIORef logSet set f `finally` flushLog +withFileLoggingUsing :: (MonadBaseControl IO m, MonadIO m)+ => LoggingLogger -> FilePath -> m a -> m a+withFileLoggingUsing logf path f = do+ liftIO $ do+ writeIORef logFunction logf+ set <- newFileLoggerSet defaultBufSize path+ atomicWriteIORef logSet set+ f `finally` flushLog+ -- | Flush all collected logging messages. This is automatically called by -- 'withStdoutLogging' and 'withStderrLogging' when those blocks are exited -- by whatever means.@@ -183,7 +226,9 @@ flushLogStr set instance MonadLogger IO where- monadLoggerLog = loggingLogger+ monadLoggerLog a b c d = do+ logf <- readIORef logFunction+ getLoggingLogger logf a b c d -- | Synonym for 'Control.Monad.Logger.logInfoN'. This module provides a -- 'MonadLogger' instance for IO, so this function can be used directly in
logging.cabal view
@@ -1,5 +1,5 @@ Name: logging-Version: 1.4.1+Version: 2.1.0 Synopsis: Simplified logging in IO for application writers. License-file: LICENSE License: MIT@@ -44,11 +44,11 @@ base >= 3 && < 5 , binary >= 0.5.1.1 , bytestring >= 0.9.2.1- , fast-logger >= 2.1.5+ , fast-logger >= 2.2.0 , old-locale >= 1.0.0.5 , time >= 1.4 , monad-control >= 0.3.2.3- , monad-logger >= 0.3.4.0+ , monad-logger >= 0.3.7.1 , text >= 0.11.3.1 , transformers >= 0.3.0.0 , lifted-base >= 0.2.2.0