firebird.lib.log

Module for parsing Firebird server log.

Enumerations

class firebird.lib.log.Severity(value)[source]

Bases: IntEnum

Standard severity levels for Firebird log messages.

CRITICAL = 4
ERROR = 3
INFO = 1
UNKNOWN = 0
WARNING = 2
class firebird.lib.log.Facility(value)[source]

Bases: IntEnum

Identifies the Firebird server facility originating a log message.

AUTH = 11
CONFIG = 2
FILEIO = 4
GUARDIAN = 9
INTL = 3
NET = 10
PLUGIN = 8
SWEEP = 7
SYSTEM = 1
UNKNOWN = 0
USER = 5
VALIDATION = 6

Dataclasses

class firebird.lib.log.LogMessage(origin: str, timestamp: datetime, level: Severity, code: int, facility: Facility, message: str, params: dict[str, Any])[source]

Bases: object

Represents a single, parsed entry from the Firebird log.

Instances are immutable and orderable by timestamp.

Parameters:
code: int

Message identification code

facility: Facility

Firebird server facility that wrote the message

level: Severity

Severity level

message: str

Message text. It may contain str.format() style {param_name} placeholders for message parameters found in the params dictionary.

origin: str

Firebird server identification

params: dict[str, Any]

Dictionary containing parameters extracted from the log message text.

timestamp: datetime

Date and time when message was written to log

Classes

class firebird.lib.log.LogParser[source]

Bases: object

A 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 the parse() 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, calls push() for each line, and yields complete LogMessage objects as they are parsed. It automatically handles the final push(STOP) call.

Parameters:

lines (Iterable) – An iterable yielding lines from a Firebird log (e.g., a file object or list of strings).

Yields:

LogMessage instances 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_entry contains 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 LogMessage instance representing the parsed entry. If the specific message cannot be identified via logmsgs, a generic LogMessage with Severity.UNKNOWN and Facility.UNKNOWN is returned.

Raises:

firebird.base.types.Error – If the first line doesn’t conform to the expected log entry header format (origin + timestamp).

Return type:

LogMessage

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 STOP sentinel is received, it attempts to parse the buffered lines into a complete LogMessage.

Parameters:

line (str | STOP) – Single line from Firebird log, or the STOP sentinel to signal the end of input and process any remaining buffered lines.

Returns:

A LogMessage instance if a complete log entry was parsed from the buffer, or None if more lines are needed for the current entry. Returns the final entry when STOP is pushed and the buffer is non-empty.

Return type:

LogMessage | None