Simple log buffer implementation for event and trend logs. The type of the item is not enforced.
The log buffer can maintain a maximum buffer size by dropping the oldest item on overflow (ring buffer).
Summary
Types
Log buffer item type.
Implementation detail and thus private API. Changes to it do not count towards Semantic Versioning.
Representative type for the log buffer.
Functions
Checks in an item.
Checks out the oldest item in the log buffer.
Drops the specified amount of oldest items from the log buffer.
Creates a new log buffer from the given list, with an optional max size. The head of the list will be the oldest entry in the log buffer.
Get the size of the log buffer.
Creates a new log buffer with an optional max size.
Peeks into the log buffer and returns the oldest item without removing it.
Peeks into the log buffer and returns the newest item without removing it.
Reads the specified count, starting from the given position (offset), from the log buffer.
Creates a list from the log buffer.
Truncates the log buffer to size zero.
Types
@type item() :: BACnet.Protocol.EventLogRecord.t() | BACnet.Protocol.LogRecord.t() | BACnet.Protocol.LogMultipleRecord.t()
Log buffer item type.
@opaque items()
Implementation detail and thus private API. Changes to it do not count towards Semantic Versioning.
@type t() :: %BACnet.Stack.LogBuffer{ items: items(), max_size: pos_integer() | nil, size: non_neg_integer() }
Representative type for the log buffer.
Functions
Checks in an item.
If the log buffer has a max size, the max size will be maintained (meaning the oldest item gets dropped on overflow).
Checks out the oldest item in the log buffer.
If the log buffer is empty, nil will be returned as item.
@spec drop(t(), pos_integer()) :: t()
Drops the specified amount of oldest items from the log buffer.
@spec from_list(list(), pos_integer() | nil) :: t()
Creates a new log buffer from the given list, with an optional max size. The head of the list will be the oldest entry in the log buffer.
If a max size is specified, the list will be truncated to the max size (from the end). The queue length will be calculated in any case. This operation is O(n).
@spec get_size(t()) :: non_neg_integer()
Get the size of the log buffer.
@spec new(pos_integer() | nil) :: t()
Creates a new log buffer with an optional max size.
Peeks into the log buffer and returns the oldest item without removing it.
Peeks into the log buffer and returns the newest item without removing it.
@spec read_range(t(), non_neg_integer(), pos_integer()) :: [item()]
Reads the specified count, starting from the given position (offset), from the log buffer.
Creates a list from the log buffer.
Truncates the log buffer to size zero.