bittensor.utils.btlogging.format#

btlogging.format module

This module defines custom logging formatters for the Bittensor project.

Attributes#

Classes#

BtFileFormatter

BtFileFormatter

BtStreamFormatter

A custom logging formatter for the Bittensor project that overrides the time formatting to include milliseconds,

Functions#

_success(self, message, *args, **kws)

_trace(self, message, *args, **kws)

Module Contents#

class bittensor.utils.btlogging.format.BtFileFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#

Bases: logging.Formatter

BtFileFormatter

A custom logging formatter for the Bittensor project that overrides the time formatting to include milliseconds and centers the level name.

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

format(record)[source]#

Override format to center the level name.

Parameters:

record (logging.LogRecord) – The log record.

Returns:

The formatted log record.

Return type:

formatted record (str)

formatTime(record, datefmt=None)[source]#

Override formatTime to add milliseconds.

Parameters:
  • record (logging.LogRecord) – The log record.

  • datefmt (Optional[str]) – The date format string.

Returns:

The formatted time string with milliseconds.

Return type:

s (str)

class bittensor.utils.btlogging.format.BtStreamFormatter(*args, **kwargs)[source]#

Bases: logging.Formatter

A custom logging formatter for the Bittensor project that overrides the time formatting to include milliseconds, centers the level name, and applies custom log formats, emojis, and colors.

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

format(record)[source]#

Override format to apply custom formatting including emojis and colors.

This method saves the original format, applies custom formatting based on the log level and trace flag, replaces text with emojis and colors, and then returns the formatted log record.

Parameters:

record (logging.LogRecord) – The log record.

Returns:

The formatted log record.

Return type:

result (str)

formatTime(record, datefmt=None)[source]#

Override formatTime to add milliseconds.

Parameters:
  • record (logging.LogRecord) – The log record.

  • datefmt (Optional[str]) – The date format string.

Returns:

The formatted time string with milliseconds.

Return type:

s (str)

set_trace(state=True)[source]#

Change formatter state.

Parameters:

state (bool)

trace = False#
bittensor.utils.btlogging.format.DEFAULT_LOG_FORMAT: str#
bittensor.utils.btlogging.format.DEFAULT_TRACE_FORMAT: str#
bittensor.utils.btlogging.format.LOG_FORMATS: dict[int, str]#
bittensor.utils.btlogging.format.LOG_TRACE_FORMATS: dict[int, str]#
bittensor.utils.btlogging.format.SUCCESS_LEVEL_NUM: int = 21#
bittensor.utils.btlogging.format.TRACE_LEVEL_NUM: int = 5#
bittensor.utils.btlogging.format._success(self, message, *args, **kws)[source]#
Parameters:

message (str)

bittensor.utils.btlogging.format._trace(self, message, *args, **kws)[source]#
Parameters:

message (str)

bittensor.utils.btlogging.format.color_map: dict[str, str]#
bittensor.utils.btlogging.format.emoji_map: dict[str, str]#
bittensor.utils.btlogging.format.log_level_color_prefix: dict[int, str]#