Two types of logs are supported:
Appends items to a single file, which size can
be limited by the
Uses a sequence of wrap log files of limited size. As a wrap log file is filled up, further items are logged on to the next file in the sequence, starting all over with the first file when the last file is filled up.
For efficiency reasons, items are always written to files as binaries.
Two formats of the log files are supported:
Supports automatic repair of log files that are not properly closed and enables efficient reading of logged items in chunks using a set of functions defined in this module. This is the only way to read internally formatted logs. An item logged to an internally formatted log must not occupy more than 4 GB of disk space (the size must fit in 4 bytes).
Leaves it up to the user to read and interpret the logged data.
The
For each open disk log, one process handles requests
made to the disk log. This process is created when
Owners can subscribe to notifications,
messages of the form
For a disk log process to close its file properly and terminate, it must be closed by its owners and once by some non-owner process for each time the log was used anonymously. The users are counted and there must not be any users left when the disk log process terminates.
Items can be logged synchronously by using functions
When using the internal format for logs, use functions
The
A collection of open disk logs with the same name running on
different nodes is said to be a distributed disk log
if requests made to any of the logs are automatically made to
the other logs as well. The members of such a collection are
called individual distributed disk logs, or just distributed
disk logs if there is no risk of confusion. There is no order
between the members of such a collection. For example, logged
terms are not necessarily written to the node where the
request was made before written to the other nodes. However,
a few functions do not make requests to all
members of distributed disk logs, namely
An open disk log that is not a distributed disk log is said to be a local disk log. A local disk log is only accessible from the node where the disk log process runs, whereas a distributed disk log is accessible from all nodes in the Erlang system, except for those nodes where a local disk log with the same name as the distributed disk log exists. All processes on nodes that have access to a local or distributed disk log can log items or otherwise change, inspect, or close the log.
It is not guaranteed that all log files of a distributed disk log
contain the same log items. No attempt is made to synchronize
the contents of the files. However, as long as at least one of
the involved nodes is alive at each time, all items are logged.
When logging items to a distributed log, or otherwise trying to
change the log, the replies from individual logs are
ignored. If all nodes are down, the disk log functions
reply with a
In some applications, it can be unacceptable that
replies from individual logs are ignored. An alternative in such
situations is to use many local disk logs instead of one
distributed disk log, and implement the distribution without use
of the
Errors are reported differently for asynchronous log attempts
and other uses of the
The
Error message
If an attempt to reopen or truncate a log fails (see
Chunk continuation returned by
Returns the names of the disk logs accessible on the current node. The first list contains local disk logs and the second list contains distributed disk logs.
Asynchronously append an item to a disk log.
Owners subscribing to notifications receive
message
Asynchronously append a list of items to a disk log.
Owners subscribing to notifications receive
message
With a call to
Any process can probe a blocked log with
Changes the value of option
Changes the value of option
Changes the size of an open log. For a halt log, the size can always be increased, but it cannot be decreased to something less than the current file size.
For a wrap log, both the size and the number of files can always be increased, as long as the number of files does not exceed 65000. If the maximum number of files is decreased, the change is not valid until the current file is full and the log wraps to the next file. The redundant files are removed the next time the log wraps around, that is, starts to log to file number 1.
As an example, assume that the old maximum number of files is 10 and that the new maximum number of files is 6. If the current file number is not greater than the new maximum number of files, files 7-10 are removed when file 6 is full and the log starts to write to file number 1 again. Otherwise, the files greater than the current file are removed when the current file is full (for example, if the current file is 8, files 9 and 10 are removed). The files between the new maximum number of files and the current file (that is, files 7 and 8) are removed the next time file 6 is full.
If the size of the files is decreased, the change immediately affects the current log. It does not change the size of log files already full until the next time they are used.
If the log size is decreased, for example, to save space,
function
Efficiently reads the terms that are appended
to an internally formatted log. It minimizes disk
I/O by reading 64 kilobyte chunks from the file. Functions
The first time
When
When
Returns the pair
Terms are read from the disk log running on
Can be used with
If atom
If the wrap log is not full because all files are not yet
used,
The disk log process is not terminated as long as there are
owners or users of the log. All owners must close the log,
possibly by terminating. Also, any other process, not only the processes
that have opened the log anonymously, can decrement the
If the log is blocked by the closing process, the log is also unblocked.
Given the error returned by any function in this module,
this function returns a descriptive string
of the error in English. For file errors, function
Forces the internally formatted disk log to start logging to the
next log file. It can be used, for example, with
Owners subscribing to notifications normally
receive a
Returns a list of
The following pairs are returned for all logs:
For halt logs
The information returned by the
current invocation of function
If the log is local on
the current node,
The following pairs are returned for all logs opened in
Depending on the value of
the
The following pair is returned for halt logs opened in
The following pairs are returned for wrap logs opened in
The number of bytes written to the current wrap log file.
The number of items written to the current wrap log file, header inclusive.
The total number of items in all wrap log files.
The ordinal for
the current wrap log file in the range
Notice that functions
If no log with the specified name exist on the specified node,
Synchronously
appends a term to a disk log. Returns
Owners subscribing to notifications are notified
of an error with an
Synchronously appends a list of items to the log. It is more
efficient to use these functions instead of functions
Owners subscribing to notifications are notified
of an error with an
Parameter
Specifies the log name. This name must be passed on as a parameter in all subsequent logging operations. A name must always be supplied.
Specifies the name of the
file to be used for logged terms. If this value is
omitted and the log name is an atom or a string,
the filename defaults to
For wrap logs, this is the base name of the files. Each file in
a wrap log is called
If
If
The log type. Defaults to
Disk log format. Defaults to
Log size.
When a halt log has reached its maximum size, all attempts to
log more items are rejected. Defaults to
For wrap logs, parameter
Wrap logs write at most
When opening an existing wrap log, it is not
necessary to supply a value for option
This option can be used for
adding members to a distributed disk log.
Defaults to
If
Sent when a wrap log has
filled up one of its files and a new file is
opened.
Sent when a log is
truncated or reopened. For halt logs
Sent when an asynchronous log attempt is made to
a log file opened in read-only mode.
Sent when an asynchronous log attempt is made to
a blocked log that does not queue log attempts.
Sent when function
Sent when
an attempt to log items to a wrap log would write more
bytes than the limit set by option
Sent when the error status changes. The error status
is defined by the outcome of the last attempt to log
items to the log, or to truncate the log, or the last
use of function
Specifies a header to be
written first on the log file. If the log is a wrap
log, the item
Specifies a function
to be called each time a new log file is opened.
The call
Specifies if the log is to be
opened in read-only or read-write mode. Defaults to
Specifies if messages will be sent to
When a disk log is opened in read-write mode, any existing
log file is checked for. If there is none, a new empty
log is created, otherwise the existing file is opened at the
position after the last logged item, and the logging of items
starts from there. If the format is
If an owner attempts to open a log
as owner once again, it is acknowledged with the return value
If a log with a specified name is local on some node,
and one tries to open the log distributed on the same node,
the tuple
A log file can be opened more than once by giving
different values to option
If an attempt to open a log file for the first time fails,
the disk log process terminates with the EXIT message
Returns the log name
given the pid of a disk log process on the current node, or
This function is meant to be used for debugging only.
Renames the log file
to
Owners subscribing to notifications receive
a
Upon failure to reopen the log, the disk log process terminates
with the EXIT message
Ensures that the contents of the log are written to the disk. This is usually a rather expensive operation.
Removes all items from a disk log.
If argument
Owners subscribing to notifications receive
a
If the attempt to truncate the log fails, the disk log process
terminates with the EXIT message
Unblocks a log. A log can only be unblocked by the blocking process.