bittensor.utils.btlogging

Contents

bittensor.utils.btlogging#

btlogging sub-package standardized logging for Bittensor.

This module provides logging functionality for the Bittensor package. It includes custom loggers, handlers, and formatters to ensure consistent logging throughout the project.

Submodules#

Attributes#

Classes#

LoggingMachine

Handles logger states for bittensor and 3rd party libraries.

Package Contents#

class bittensor.utils.btlogging.LoggingMachine(config, name=BITTENSOR_LOGGER_NAME)[source]#

Bases: statemachine.StateMachine, logging.Logger

Handles logger states for bittensor and 3rd party libraries.

Initialize the logger with a name and an optional level.

Parameters:
Debug#
Default#
Disabled#
Info#
Trace#
Warning#
__call__(config=None, debug=None, trace=None, info=None, record_log=None, logging_dir=None)[source]#
Parameters:
property __trace_on__: bool#

Checks if the current state is in “Trace” mode.

Returns:

True if the current state is “Trace”, otherwise False.

Return type:

bool

_config#
_configure_handlers(config)[source]#
Return type:

list[logging.Handler]

_create_and_start_listener(handlers)[source]#

A listener to receive and publish log records.

This listener receives records from a queue populated by the main bittensor logger, as well as 3rd party loggers

_create_file_handler(logfile)[source]#
Parameters:

logfile (str)

_deinitialize_bt_logger(name)[source]#

Find the logger by name and remove the queue handler associated with it.

Parameters:

name (str)

_enable_file_logging(logfile)[source]#
Parameters:

logfile (str)

_enable_initial_state(config)[source]#

Set correct state action on initializing

_extract_logging_config(config)[source]#

Extract btlogging’s config from bittensor config

Parameters:

config (bittensor.core.config.Config) – Bittensor config instance.

Returns:

btlogging’s config from Bittensor config or Bittensor config.

Return type:

(dict)

_file_formatter#
_handlers#
_initialize_bt_logger(name)[source]#

Initialize logging for bittensor.

Since the initial state is Default, logging level for the module logger is INFO, and all third-party loggers are silenced. Subsequent state transitions will handle all logger outputs.

Parameters:

name (str)

_listener#
_logger#
_primary_loggers#
_queue#
_stream_formatter#
classmethod add_args(parser, prefix=None)[source]#

Accept specific arguments fro parser

Parameters:
after_disable_debug()[source]#

Logs status after disable Debug.

after_disable_trace()[source]#

Logs status after disable Trace.

after_enable_debug()[source]#

Logs status after enable Debug.

after_enable_default()[source]#
after_enable_info()#

Logs status after enable info.

after_enable_trace()[source]#

Logs status after enable Trace.

after_enable_warning()#

Logs status after enable Warning.

after_transition(event, state)[source]#

Starts listener after transition.

before_disable_debug()[source]#

Logs status before disable Debug.

before_disable_logging()[source]#

Prepares the logging system for disabling.

This method performs the following actions: 1. Logs an informational message indicating that logging is being disabled. 2. Disables trace mode in the stream formatter. 3. Sets the logging level to CRITICAL for all loggers.

This ensures that only critical messages will be logged after this method is called.

before_disable_trace()[source]#

Logs status before disable Trace.

before_enable_console()#

Logs status before enable Console.

before_enable_debug()[source]#

Logs status before enable Debug.

before_enable_default()[source]#

Logs status before enable Default.

before_enable_info()#

Logs status before enable info.

before_enable_trace()[source]#

Logs status before enable Trace.

before_enable_warning()#

Logs status before enable Warning.

before_transition(event, state)[source]#

Stops listener after transition.

check_config(config)[source]#
Parameters:

config (bittensor.core.config.Config)

classmethod config()[source]#

Get config from the argument parser.

Returns:

config object

Return type:

config (bittensor.core.config.Config)

console#
critical(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps critical message with prefix and suffix.

debug(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps debug message with prefix and suffix.

deregister_primary_logger(name)[source]#

De-registers a primary logger

This function removes the logger from the _primary_loggers set and deinitializes its queue handler

Parameters:

name (str) – the name of primary logger.

disable_debug#
disable_info#
disable_logging#
disable_third_party_loggers()[source]#

Disables logging for third-party loggers by removing all their handlers.

disable_trace#
disable_warning#
enable_console#
enable_debug#
enable_default#
enable_info#
enable_third_party_loggers()[source]#

Enables logging for third-party loggers by adding a queue handler to each.

enable_trace#
enable_warning#
error(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps error message with prefix and suffix.

exception(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps exception message with prefix and suffix.

get_config()[source]#
get_level()[source]#

Returns Logging level.

Return type:

int

get_queue()[source]#

Get the queue the QueueListener is publishing from.

To set up logging in a separate process, a QueueHandler must be added to all the desired loggers.

help()[source]#
info(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps info message with prefix and suffix.

off()[source]#

Disables all states.

on()[source]#

Enable default state.

register_primary_logger(name)[source]#

Register a logger as primary logger

This adds a logger to the _primary_loggers set to ensure it doesn’t get disabled when disabling third-party loggers. A queue handler is also associated with it.

Parameters:

name (str) – the name for primary logger.

set_config(config)[source]#

Set config after initialization, if desired.

Parameters:

config (bittensor.core.config.Config) – Bittensor config instance.

set_console()#

Sets Console state.

set_debug(on=True)[source]#

Sets Debug state.

Parameters:

on (bool)

set_default()#

Sets Default state.

set_info(on=True)#

Sets Info state.

Parameters:

on (bool)

set_trace(on=True)[source]#

Sets Trace state.

Parameters:

on (bool)

set_warning(on=True)#

Sets Warning state.

Parameters:

on (bool)

success(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps success message with prefix and suffix.

trace(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps trace message with prefix and suffix.

warning(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#

Wraps warning message with prefix and suffix.

bittensor.utils.btlogging.logging#