Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A log is a stack of entries that supports efficient pushing of new entries and fetching of old. It can be considered an extendible array of entries.
Synopsis
- data FileLog object = FileLog {
- logIdentifier :: LogKey object
- logCurrent :: MVar FHandle
- logNextEntryId :: TVar EntryId
- logQueue :: TVar ([ByteString], [IO ()])
- logThreads :: [ThreadId]
- data LogKey object = LogKey {
- logDirectory :: FilePath
- logPrefix :: String
- logSerialiser :: Serialiser object
- logArchiver :: Archiver
- type EntryId = Int
- openFileLog :: LogKey object -> IO (FileLog object)
- closeFileLog :: FileLog object -> IO ()
- pushEntry :: FileLog object -> object -> IO () -> IO ()
- pushAction :: FileLog object -> IO () -> IO ()
- ensureLeastEntryId :: FileLog object -> EntryId -> IO ()
- readEntriesFrom :: FileLog object -> EntryId -> IO [object]
- rollbackTo :: LogKey object -> EntryId -> IO ()
- rollbackWhile :: LogKey object -> (object -> Bool) -> IO ()
- newestEntry :: LogKey object -> IO (Maybe object)
- askCurrentEntryId :: FileLog object -> IO EntryId
- cutFileLog :: FileLog object -> IO EntryId
- archiveFileLog :: FileLog object -> EntryId -> IO ()
- findLogFiles :: LogKey object -> IO [(EntryId, FilePath)]
Documentation
FileLog | |
|
LogKey | |
|
openFileLog :: LogKey object -> IO (FileLog object) Source #
closeFileLog :: FileLog object -> IO () Source #
pushEntry :: FileLog object -> object -> IO () -> IO () Source #
Schedule a new log entry. This call does not block. The given IO action runs once the object is durable. The IO action blocks the serialization of events so it should be swift.
pushAction :: FileLog object -> IO () -> IO () Source #
The given IO action is executed once all previous entries are durable.
ensureLeastEntryId :: FileLog object -> EntryId -> IO () Source #
readEntriesFrom :: FileLog object -> EntryId -> IO [object] Source #
Read all durable entries younger than the given EntryId
. Note that
entries written during or after this call won't be included in the returned
list.
rollbackTo :: LogKey object -> EntryId -> IO () Source #
Obliterate log entries younger than or equal to the EntryId
. Very unsafe,
can't be undone
:: LogKey object | |
-> (object -> Bool) | the filter function |
-> IO () |
Obliterate log entries as long as the filter function returns True
.
newestEntry :: LogKey object -> IO (Maybe object) Source #
Finds the newest entry in the log. Doesn't work on open logs. Do not use after the log has been opened.
Implementation:
- Search the newest log files first.
- Once a file containing at least one valid entry is found, return the last entry in that file.
askCurrentEntryId :: FileLog object -> IO EntryId Source #
cutFileLog :: FileLog object -> IO EntryId Source #
archiveFileLog :: FileLog object -> EntryId -> IO () Source #
Move all log files that do not contain entries equal or higher than the
given entryId into an Archive/
directory.
findLogFiles :: LogKey object -> IO [(EntryId, FilePath)] Source #