rotating-log 0.2 → 0.4
raw patch · 2 files changed
+34/−17 lines, 2 filesdep −old-localedep ~basedep ~bytestringdep ~directory
Dependencies removed: old-locale
Dependency ranges changed: base, bytestring, directory, filepath, time
Files
- rotating-log.cabal +10/−10
- src/System/RotatingLog.hs +24/−7
rotating-log.cabal view
@@ -1,6 +1,7 @@ name: rotating-log-version: 0.2-description: Size-limited, concurrent, automatically-rotating log writer for production applications.+version: 0.4+description: Size-limited, concurrent, automatically-rotating log writer.+Synopsis: Size-limited, concurrent, automatically-rotating log writer. license: BSD3 license-file: LICENSE author: Ozgun Ataman, Doug Beardsley@@ -9,6 +10,7 @@ category: Logging build-type: Simple cabal-version: >= 1.8+homepage: http://github.com/Soostone/rotating-log library hs-source-dirs: src@@ -19,8 +21,7 @@ build-depends: base >= 4 && < 5, bytestring >= 0.8,- old-locale >= 1.0,- time >= 1.1,+ time >= 1.5 && < 1.7, filepath >= 1.0, directory >= 1.0 @@ -32,11 +33,10 @@ ghc-options: -Wall hs-source-dirs: test, src build-depends:- base >= 4,- bytestring >= 0.8,- old-locale >= 1.0,- time >= 1.1,- filepath >= 1.0,- directory >= 1.0+ base, + bytestring,+ time, + filepath, + directory ghc-options: -Wall -fwarn-tabs -threaded
src/System/RotatingLog.hs view
@@ -20,6 +20,7 @@ , mkRotatingLog , rotatedWrite , rotatedWrite'+ , rotatedClose -- * Built-In Post-Rotate Actions , archiveFile@@ -35,7 +36,6 @@ import System.Directory import System.FilePath.Posix import System.IO-import System.Locale ------------------------------------------------------------------------------- @@ -107,6 +107,27 @@ rotatedWrite' rlog t bs +-------------------------------------------------------------------------------+-- | Close the underlying file handle and apply the post-action hook.+rotatedClose :: RotatingLog -> IO ()+rotatedClose r = do+ li <- readMVar (logInfo r)+ now <- getCurrentTime+ closeFile r li now+++-------------------------------------------------------------------------------+-- | Close current file and apply post action.+closeFile :: RotatingLog -> LogInfo -> UTCTime -> IO ()+closeFile RotatingLog{..} LogInfo{..} now = do+ hClose curHandle+ let newFile = logFileName namePrefix now+ renameFile curFile newFile+ postAction newFile+ where+ curFile = curLogFileName namePrefix++ ------------------------------------------------------------------------------ -- | Writes ByteString to a rotating log file. If this write would exceed the -- size limit, then the file is closed and a new file opened. This function@@ -118,12 +139,9 @@ -- content. rotatedWrite' :: RotatingLog -> UTCTime -> ByteString -> IO () rotatedWrite' rl@RotatingLog{..} t bs = do- modifyMVar_ logInfo $ \LogInfo{..} -> do+ modifyMVar_ logInfo $ \ li@LogInfo{..} -> do (h,b) <- if bytesWritten + len > sizeLimit- then do hClose curHandle- let newFile = logFileName namePrefix t- renameFile curFile newFile- postAction newFile+ then do closeFile rl li t h <- openLogFile rl return (h, 0) else return (curHandle, bytesWritten)@@ -131,7 +149,6 @@ return $! LogInfo h (len + b) where len = fromIntegral $ B.length bs- curFile = curLogFileName namePrefix -------------------------------------------------------------------------------