oslo_log.formatters

class oslo_log.formatters.ContextFormatter(*args: Any, **kwargs: Any)

Bases: Formatter

A context.RequestContext aware formatter configured through flags.

The flags used to set format strings are: logging_context_format_string and logging_default_format_string. You can also specify logging_debug_format_suffix to append extra formatting if the log level is debug.

The standard variables available to the formatter are listed at: http://docs.python.org/library/logging.html#formatter

In addition to the standard variables, one custom variable is available to both formatting string: isotime produces a timestamp in ISO8601 format, suitable for producing RFC5424-compliant log messages.

Furthermore, logging_context_format_string has access to all of the data in a dict representation of the context.

format(record: LogRecord) str

Uses contextstring if request_id is set, otherwise default.

formatException(ei: tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None], *, record: LogRecord | None = None) str

Format exception output with CONF.logging_exception_prefix.

class oslo_log.formatters.FluentFormatter(fmt: str | None = None, datefmt: str | None = None, style: str = '%')

Bases: Formatter

A formatter for fluentd.

format() returns dict, not string. It expects to be used by fluent.handler.FluentHandler. (included in fluent-logger-python)

Added in version 3.17.

format(record: LogRecord) Any

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

formatException(ei: tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None], *, strip_newlines: bool = True) str

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

class oslo_log.formatters.JSONFormatter(fmt: str | None = None, datefmt: str | None = None, style: str = '%')

Bases: Formatter

format(record: LogRecord) str

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

formatException(ei: tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None], *, strip_newlines: bool = True) str

Format and return the specified exception information as a string.

This default implementation just uses traceback.print_exception()

class oslo_log.formatters.JSONLogRecord

Bases: TypedDict

args: Any
asctime: str
context: dict[str, Any]
created: float
error_summary: str
extra: dict[str, Any]
filename: str
funcname: str
hostname: str | None
levelname: str
levelno: int
lineno: int
message: str
module: str
msecs: float
msg: str
name: str
pathname: str
process: int | None
process_name: str | None
relative_created: float
thread: int | None
thread_name: str | None
traceback: str | None