bittensor.utils.btlogging.loggingmachine#
Module provides a logging framework for Bittensor, managing both Bittensor-specific and third-party logging states. It leverages the StateMachine from the statemachine package to transition between different logging states such as Default, Debug, Trace, and Disabled.
Attributes#
Classes#
Named tuple to hold the logging configuration. |
|
Handles logger states for bittensor and 3rd party libraries. |
Module Contents#
- bittensor.utils.btlogging.loggingmachine.CUSTOM_LOGGER_METHOD_STACK_LEVEL = 2#
- class bittensor.utils.btlogging.loggingmachine.LoggingConfig[source]#
Bases:
NamedTuple
Named tuple to hold the logging configuration.
- class bittensor.utils.btlogging.loggingmachine.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:
config (bittensor.core.config.Config)
name (str)
- Debug#
- Default#
- Disabled#
- Info#
- Trace#
- Warning#
- classmethod add_args(parser, prefix=None)[source]#
Accept specific arguments fro parser
- Parameters:
parser (argparse.ArgumentParser)
prefix (str)
- 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.
- 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_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.
- info(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#
Wraps info message with prefix and suffix.
- 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.
- success(msg='', prefix='', suffix='', *args, stacklevel=1, **kwargs)[source]#
Wraps success message with prefix and suffix.