bittensor.btlogging.format#

btlogging.format module

This module defines custom logging formatters for the Bittensor project.

Attributes#

Classes#

BtStreamFormatter

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

BtFileFormatter

BtFileFormatter

Functions#

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

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

Module Contents#

bittensor.btlogging.format.TRACE_LEVEL_NUM: int = 5#
bittensor.btlogging.format.SUCCESS_LEVEL_NUM: int = 21#
bittensor.btlogging.format._trace(self, message, *args, **kws)[source]#
Parameters:

message (str)

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

message (str)

bittensor.btlogging.format.emoji_map: Dict[str, str]#
bittensor.btlogging.format.color_map: Dict[str, str]#
bittensor.btlogging.format.log_level_color_prefix: Dict[int, str]#
bittensor.btlogging.format.LOG_FORMATS: Dict[int, str]#
bittensor.btlogging.format.LOG_TRACE_FORMATS: Dict[int, str]#
bittensor.btlogging.format.DEFAULT_LOG_FORMAT: str#
bittensor.btlogging.format.DEFAULT_TRACE_FORMAT: str#
class bittensor.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.

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

Override formatTime to add milliseconds.

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

  • datefmt (str, optional) – The date format string.

Returns:

The formatted time string with milliseconds.

Return type:

s (str)

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)

set_trace(state=True)[source]#

Change formatter state.

Parameters:

state (bool)

class bittensor.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.

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

Override formatTime to add milliseconds.

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

  • datefmt (str, optional) – The date format string.

Returns:

The formatted time string with milliseconds.

Return type:

s (str)

format(record)[source]#

Override format to center the level name.

Parameters:

record (logging.LogRecord) – The log record.

Returns:

The formatted log record.

Return type:

formated record (str)