ButlerLogRecords¶
- class lsst.daf.butler.logging.ButlerLogRecords(records: list[lsst.daf.butler.logging.ButlerLogRecord], extra: dict[str, object] | None = None)¶
Bases:
MutableSequence[ButlerLogRecord]A container class for
ButlerLogRecordobjects.- Parameters:
- records
list[ButlerLogRecord] List of records to use directly as the backing store for the container.
- extra
dict, optional Additional JSON data included with the log records. Subclasses may interpret structured information, but the base class just sets this as the
extraattribute.
- records
Notes
ButlerLogRecords supports two different file formats:
Full-container serialization to JSON, in which records are stored in a
recordsarray and extra fields may be present (for backwards compatibility, reading records directly from a JSON list is also supported).Streaming serialization, in which each each line is a one-line JSON representation of a single
ButlerLogRecord. Extra fields may be added included to this format by appending a single line with the value given bySTREAMING_EXTRA_DELIMITER, which indicates that the remainder of the file is a single JSON block.
Subclasses of
ButlerLogRecordsare expected to support these formats by using the “extra” JSON fields to hold any additional state. If subclasses interceptextraat construction in a way that prevents that information from being held in the base classextrafield, they must override_from_record_subsetandto_json_datato pass that state to slices and save it, respectively.Attributes Summary
Special string written (on its own line) after streamed log records to indicate that the rest of the file is a JSON blob of "extra" data.
The log format string for these records.
Methods Summary
append(value)S.append(value) -- append value to the end of the sequence
from_file(filename)Read records from file.
from_raw(serialized)Parse raw serialized form and return records.
from_records(records[, extra])Create collection from iterable.
from_stream(stream)Read records from I/O stream.
insert(index, value)S.insert(index, value) -- insert value before index
set_log_format(format)Set the log format string for these records.
Serialize to a JSON string.
write_streaming_extra(file, extra_data)Append the special delimiter and extra JSON data to a file written in streaming mode.
Attributes Documentation
- STREAMING_EXTRA_DELIMITER: ClassVar[str] = '###EXTRA###'¶
Special string written (on its own line) after streamed log records to indicate that the rest of the file is a JSON blob of “extra” data.
- log_format¶
The log format string for these records.
Methods Documentation
- append(value: LogRecord | ButlerLogRecord) None¶
S.append(value) – append value to the end of the sequence
- classmethod from_file(filename: str) Self¶
Read records from file.
- Parameters:
- filename
str Name of file containing the JSON records.
- filename
Notes
Works with one-record-per-line format JSON files and a direct serialization of the Pydantic model.
- classmethod from_raw(serialized: str | bytes) ButlerLogRecords¶
Parse raw serialized form and return records.
- Parameters:
- serialized
bytesorstr Either the serialized JSON of the model created using
writeor a streaming format of one JSONButlerLogRecordper line. This can also support a zero-length string.
- serialized
- Returns:
- container
ButlerLogRecords New log record container.
- container
- classmethod from_records(records: Iterable[ButlerLogRecord], extra: dict[str, object] | None = None) Self¶
Create collection from iterable.
- Parameters:
- recordsiterable of
ButlerLogRecordorLogRecord The records to seed this class with.
- extra
dict, optional Additional JSON data included with the log records. Subclasses may interpret structured information, but the base class just sets this as the
extraattribute.
- recordsiterable of
- Returns:
- container
ButlerLogRecords New log record container.
- container
- classmethod from_stream(stream: IO) Self¶
Read records from I/O stream.
- Parameters:
- stream
typing.IO Stream from which to read JSON records.
- stream
- Returns:
- container
ButlerLogRecords New log record container.
- container
- insert(index: int, value: LogRecord | ButlerLogRecord) None¶
S.insert(index, value) – insert value before index