firebird.lib.log¶
Module for parsing Firebird server log.
Enumerations¶
Dataclasses¶
- class firebird.lib.log.LogMessage(origin: str, timestamp: datetime, level: Severity, code: int, facility: Facility, message: str, params: dict[str, Any])[source]¶
Bases:
objectRepresents a single, parsed entry from the Firebird log.
Instances are immutable and orderable by timestamp.
- Parameters:
Classes¶
- class firebird.lib.log.LogParser[source]¶
Bases:
objectA stateful parser for Firebird server log files (
firebird.log).It processes the log line by line, handling multi-line entries. Use the
push()method for incremental parsing or theparse()method to process an entire iterable of lines.- parse(lines: Iterable) Generator[LogMessage, None, None][source]¶
Parses Firebird log lines from an iterable source.
This is a convenience method that iterates over
lines, callspush()for each line, and yields completeLogMessageobjects as they are parsed. It automatically handles the finalpush(STOP)call.- Parameters:
lines (Iterable) – An iterable yielding lines from a Firebird log (e.g., a file object or list of strings).
- Yields:
LogMessageinstances describing individual log entries.- Raises:
firebird.base.types.Error – When a malformed log entry header is detected by
parse_entry.- Return type:
Generator[LogMessage, None, None]
- parse_entry(log_entry: list[str]) LogMessage[source]¶
Parses a single, complete log entry from a list of lines.
Assumes
log_entrycontains all lines belonging to exactly one log entry, with the first line being the header containing timestamp and origin.- Parameters:
log_entry (list[str]) – List of strings representing the lines of a single log entry.
- Returns:
A
LogMessageinstance representing the parsed entry. If the specific message cannot be identified vialogmsgs, a genericLogMessagewithSeverity.UNKNOWNandFacility.UNKNOWNis returned.- Raises:
firebird.base.types.Error – If the first line doesn’t conform to the expected log entry header format (origin + timestamp).
- Return type:
- push(line: str | STOP) LogMessage | None[source]¶
Pushes a single line (or STOP sentinel) into the parser.
This method accumulates lines in an internal buffer. When a new log entry starts or the
STOPsentinel is received, it attempts to parse the buffered lines into a completeLogMessage.- Parameters:
line (str | STOP) – Single line from Firebird log, or the
STOPsentinel to signal the end of input and process any remaining buffered lines.- Returns:
A
LogMessageinstance if a complete log entry was parsed from the buffer, orNoneif more lines are needed for the current entry. Returns the final entry whenSTOPis pushed and the buffer is non-empty.- Return type:
LogMessage | None