oslo_log.formatters

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

基类: Formatter

一个感知 context.RequestContext 的格式化器,通过 flags 配置。

用于设置格式字符串的 flags 包括:logging_context_format_string 和 logging_default_format_string。 还可以指定 logging_debug_format_suffix,以便在日志级别为 debug 时追加额外的格式。

格式化器可用的标准变量列于:https://docs.pythonlang.cn/library/logging.html#formatter

除了标准变量外,一个自定义变量可用于两种格式化字符串:isotime 生成 ISO8601 格式的时间戳,适用于生成符合 RFC5424 标准的日志消息。

此外,logging_context_format_string 可以访问 context 的字典表示形式中的所有数据。

format(record)

如果设置了 request_id,则使用 contextstring,否则使用默认值。

formatException(exc_info, record=None)

使用 CONF.logging_exception_prefix 格式化异常输出。

class oslo_log.formatters.FluentFormatter(fmt=None, datefmt=None, style='%s')

基类: Formatter

用于 fluentd 的格式化器。

format() 返回字典,而不是字符串。 它预计会被 fluent.handler.FluentHandler 使用。(包含在 fluent-logger-python 中)

在版本 3.17 中添加。

format(record)

将指定的记录格式化为文本。

记录的属性字典用作字符串格式化操作的操作数,该操作产生返回的字符串。 在格式化字典之前,执行几个准备步骤。 使用 LogRecord.getMessage() 计算记录的消息属性。 如果格式化字符串使用时间(通过调用 usesTime() 确定),则调用 formatTime() 格式化事件时间。 如果有异常信息,则使用 formatException() 格式化并附加到消息。

formatException(exc_info, strip_newlines=True)

格式化并返回指定的异常信息作为字符串。

此默认实现只是使用 traceback.print_exception()

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

基类: Formatter

format(record)

将指定的记录格式化为文本。

记录的属性字典用作字符串格式化操作的操作数,该操作产生返回的字符串。 在格式化字典之前,执行几个准备步骤。 使用 LogRecord.getMessage() 计算记录的消息属性。 如果格式化字符串使用时间(通过调用 usesTime() 确定),则调用 formatTime() 格式化事件时间。 如果有异常信息,则使用 formatException() 格式化并附加到消息。

formatException(ei, strip_newlines=True)

格式化并返回指定的异常信息作为字符串。

此默认实现只是使用 traceback.print_exception()