Copyright | Soostone Inc |
---|---|
License | BSD3 |
Maintainer | admin@soostone.com |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell98 |
Convenient logging to a disk-based log file with automatic file rotation based on size.
- data RotatingLog
- mkRotatingLog :: String -> Word64 -> BufferMode -> (FilePath -> IO ()) -> IO RotatingLog
- rotatedWrite :: RotatingLog -> ByteString -> IO ()
- rotatedWrite' :: RotatingLog -> UTCTime -> ByteString -> IO ()
- rotatedClose :: RotatingLog -> IO ()
- archiveFile :: FilePath -> FilePath -> IO ()
Core API
data RotatingLog Source
A size-limited rotating log. Log filenames are of the format prefix_timestamp.log.
:: String | A prefix for the written log files. |
-> Word64 | A size limit in bytes. |
-> BufferMode | A buffering mode for output; we leave it to you to decide how often the file should be flushed. |
-> (FilePath -> IO ()) | An action to be performed on the finished file following rotation. For example, you could give a callback that moves or ships the files somewhere else. |
-> IO RotatingLog |
Creates a rotating log given a prefix and size limit in bytes.
rotatedWrite :: RotatingLog -> ByteString -> IO () Source
Like "rotatedWrite'", but doesn't need a UTCTime and obtains it with a syscall.
rotatedWrite' :: RotatingLog -> UTCTime -> ByteString -> IO () Source
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 takes a UTCTime to allow a cached time to be used to avoid a system call.
Please note this function does NOT implicitly insert a newline at the end of the string you provide. This is so that it can be used to log non-textual streams such as binary serialized or compressed content.
rotatedClose :: RotatingLog -> IO () Source
Close the underlying file handle and apply the post-action hook.
Built-In Post-Rotate Actions
A built-in post-rotate action that moves the finished file to a given archive location.