Skip to content

Commit 27bf3db

Browse files
basfromanibraheem-abeWatchmakergarrett-opentensor
authored
Implement warning logging level (#2323)
* Make version.py bittensor import independent * Update setup.py, replace file with the __version__ * Update settings.py * Make axon independent of bittensor import. Fix axon tests. * Make chain_data.py independent of bittensor import. Fix chain_data tests. * Make dendrite.py independent of bittensor import. Fix dendrite tests. * Make staking.py independent of bittensor import. Fix staking tests. * Make subtensor.py independent of bittensor import. Fix subtensor tests. * Make prometheus.py independent of bittensor import. Fix prometheus tests. * Axon refactoring * Move subnets.py into bittensor/utils since this module is not used within the bittensor package, but is actively used by the community. * Make synapse.py independent of bittensor import. Fix synapse tests. * Make tensor.py independent of bittensor import. Fix tensor tests. * Change name `bittensor.utils.hash` -> `bittensor.utils.get_hash` * Moved from using `import bittensor` (withing bittensor codebase) to direct imports of modules and other objects. It helped to avoid namespace conflicts. * Add backwards compatibility for 'bittensor.api.extrinsics' as 'bittensor.extrinsics' * Move the contents of `wallet_utils.py` to `bittensor/utils/__init__.py`, since it is used directly from utils. * Delete `bccli` staff and related tests. Fix setup.py. * Fix tests. * Makes the `bittensor.utils.mock` subpackage available as `bittensor.mock` for backwards compatibility. * Check for participation before nomination call * Ruff formatting. Fix ruff's complaints. * Removing obsolete, unused (community and bittensor) code * Move backwards compatibility related content to `bittensor/utils/backwards_compatibility` subpackage * btlogging/loggingmachine.py improvement from #2155 * Fixes after `Merge streaming fix to staging` from #2183 * Review fix. * Remove black from dev requirements. * black back * Remove space from prod.txt. Remove black from dev.txt * Add dendrite reference to backwords compatibility * Fix the usage of env vars in default settings. * ruff * Change the subpackage name to `deprecated` * Update __version__ until 8.0.0 * Move `subnets.py` to `bittensor/utils` as it is considered more utility than deprecated. * Rename test module * Add aliases mapping test * ruff * Init: Adds initial e2e tests * Ruff * Fixes LOCALNET_SH_PATH env_var * Adds module description * Adds commit-reveal back and adds e2e for liquid alpha & commit reveal * Review suggestions implemented * Fixes logging string * Enhance: Switch from format() to f-strings * ruff * Optimize imports * Add the opportunity to run `python - m bittensor` * replace deps link from https to ssh * Fixes metagraph save/load for neurons, added e2e tests (metagraph + extrinsics) * Renamed test * Adds missing statements * increase subtensor.py test coverage until 80% * ruff * add tests * ruff * add tests _do_serve_prometheus * add tests neuron_for_uid * sort tests by group * sort tests by group * remove unused import * add test for `get_neuron_for_pubkey_and_subnet` * Add unit tests to subtensor.py * Fix ruff + `test_do_set_weights_no_waits` description * add tests * ruff + add tests * ruff * add test * fix unused imports * Config refactoring * Remove duplicated tests * add test * remove duplicated import * remove unused functions * remove unused functions + add tests * ruff * fix type annotation * add tests * Add tests and remove unused functions * fix test * ruff * Add balance tests, small refactoring * Add init test for bittensor * ruff * Add tests for utils.weight_utils.py * add tests for bittensor.utils.subnets * ruff * update test file * Decoupling chain_data.py to sub-package * Fix test * ruff * review fix * update `requirements/prod.txt` * Update localnet entrypoint port * Add substrate reconnection logic * Fix tests + add tests * Ruff formatter * add docstring to the decorator * update requirements * update requirements * update requirements * cleanup __init__.py * - move `extrinsics` from deprecated into `bittensor/core`; - update `deprecated` sub-package to `deprecated.py` module. * update ssh to https in requirements * add reconnection logic for correctly closed connection * remove unused import * fix pagination * Move do_* methods into the related extrinsic module (commit_weights.py). * Move do_* methods into the related extrinsic module (bittensor/core/extrinsics/set_weights.py). * Move do_* methods into the related extrinsic module (bittensor/core/extrinsics/transfer.py). + ruff * Move do_* methods into the related extrinsic module (bittensor/core/extrinsics/serving.py) * Move do_* methods into the related extrinsic module (bittensor/core/extrinsics/prometheus.py) * bug fixes * extrinsics refactoring * bug fix * ruff * fix * removed exit sys call for ConnectionRefusedError in _get_substrate * remove unused import * change the log message * Corrected arguments order in logging methods + test * fix integration test * ruff * comments fixes * fix `bittensor/core/subtensor.py:445: error: Argument "logger" to "retry" has incompatible type "LoggingMachine"; expected "Logger | None" [arg-type]` * integrate `bt_decode` into BTSDK * fix logger linter checker * Reverts logging enhancement * remove unused code and tests * remove unused imports * modification of error formatter, moved the submit_extrinsic call to utils.py, fixed the subtensor.py regarding extrinsics calls, fixed tests * ruff * Improved logic for concatenating message, prefix, and suffix in bittensor logging + test * fix + ruff * remove unused import * improve btlogging concat test * docs AxonInfo * docs DelegateInfo * DelegateInfoLite * IPInfo * NeuronInfo * NeuronInfo + NeuronInfoLite * PrometheusInfo * ProposalVoteData * ScheduledColdkeySwapInfo * ProposalVoteData * StakeInfo * StakeInfo + SubnetHyperparameters * bittensor/core/chain_data/utils.py * bittensor/core/axon.py * bittensor/core/axon.py * bittensor/core/config.py * bittensor/core/dendrite.py * bittensor/core/metagraph.py * bittensor/core/stream.py * bittensor/core/subtensor.py * bittensor/core/synapse.py * bittensor/core/tensor.py * replace Tuple, Dict, List, Set to python native types * bittensor/__init__.py * bittensor/utils/weight_utils.py * bittensor/utils/version.py * bittensor/utils/btlogging * fix * remove wrong `optional` from docstring's annotations * apply camel case rule * bittensor/core/extrinsics/commit_weights.py * bittensor/core/extrinsics/prometheus.py * bittensor/core/extrinsics/serving.py * axon improvement (add annotation) * README updates for SDK * bittensor/core/extrinsics/set_weights.py * bittensor/core/extrinsics/transfer.py * fix * weight_utils.py * check up and fix * fix Axon Signature * fix axon * delete unused import * update GPG * remove unused code, remove old tests, add new tests * fix * temp commented line * fix review comments * fix review comments * Adding TOC and working in review comments. * Adding installation options * Formatting adjustments for html display * Ruff formatted * Example reformatted * update metagraph * update dendrite.py * Update README.md Co-authored-by: garrett-opentensor <156717492+garrett-opentensor@users.noreply.github.com> * Update README.md Co-authored-by: garrett-opentensor <156717492+garrett-opentensor@users.noreply.github.com> * Update README.md * Update axon.py * fix tests/unit_tests/test_axon.py * Update README.md * set `WARNING` level ad default logging level * fix test * implement warning version, do info the same as default level * fix * ruff * cleanup * Change warning to debug for local connection information * update deps * remove unused file --------- Co-authored-by: ibraheem-opentensor <165814940+ibraheem-opentensor@users.noreply.github.com> Co-authored-by: ibraheem-opentensor <ibraheem@opentensor.dev> Co-authored-by: Watchmaker <rajk@opentensor.dev> Co-authored-by: garrett-opentensor <156717492+garrett-opentensor@users.noreply.github.com>
1 parent bff05c0 commit 27bf3db

File tree

4 files changed

+101
-25
lines changed

4 files changed

+101
-25
lines changed

bittensor/__init__.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,6 @@
2222
from .utils.deprecated import *
2323

2424

25-
# Logging helpers.
26-
def trace(on: bool = True):
27-
"""
28-
Enables or disables trace logging.
29-
30-
Args:
31-
on (bool): If True, enables trace logging. If False, disables trace logging.
32-
"""
33-
logging.set_trace(on)
34-
35-
36-
def debug(on: bool = True):
37-
"""
38-
Enables or disables debug logging.
39-
40-
Args:
41-
on (bool): If True, enables debug logging. If False, disables debug logging.
42-
"""
43-
logging.set_debug(on)
44-
45-
4625
def __getattr__(name):
4726
if name == "version_split":
4827
warnings.warn(

bittensor/core/subtensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ def __init__(
175175
logging.info(
176176
f"You are connecting to {self.network} network with endpoint {self.chain_endpoint}."
177177
)
178-
logging.warning(
178+
logging.debug(
179179
"We strongly encourage running a local subtensor node whenever possible. "
180180
"This increases decentralization and resilience of the network."
181181
)
182-
logging.warning(
182+
logging.debug(
183183
"In a future release, local subtensor will become the default endpoint. "
184184
"To get ahead of this change, please run a local subtensor node and point to it."
185185
)

bittensor/utils/btlogging/loggingmachine.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,48 @@ class LoggingMachine(StateMachine, Logger):
6969
Debug = State()
7070
Trace = State()
7171
Disabled = State()
72+
Warning = State()
7273

7374
enable_default = (
7475
Debug.to(Default)
7576
| Trace.to(Default)
7677
| Disabled.to(Default)
7778
| Default.to(Default)
79+
| Warning.to(Default)
7880
)
7981

82+
enable_info = enable_default
83+
8084
enable_trace = (
81-
Default.to(Trace) | Debug.to(Trace) | Disabled.to(Trace) | Trace.to(Trace)
85+
Default.to(Trace)
86+
| Debug.to(Trace)
87+
| Disabled.to(Trace)
88+
| Trace.to(Trace)
89+
| Warning.to(Trace)
8290
)
8391

8492
enable_debug = (
85-
Default.to(Debug) | Trace.to(Debug) | Disabled.to(Debug) | Debug.to(Debug)
93+
Default.to(Debug)
94+
| Trace.to(Debug)
95+
| Disabled.to(Debug)
96+
| Debug.to(Debug)
97+
| Warning.to(Debug)
98+
)
99+
100+
enable_warning = (
101+
Default.to(Warning)
102+
| Trace.to(Warning)
103+
| Disabled.to(Warning)
104+
| Debug.to(Warning)
105+
| Warning.to(Warning)
86106
)
87107

88108
disable_trace = Trace.to(Default)
89109

90110
disable_debug = Debug.to(Default)
91111

112+
disable_warning = Warning.to(Default)
113+
92114
disable_logging = (
93115
Trace.to(Disabled)
94116
| Debug.to(Disabled)
@@ -308,9 +330,29 @@ def before_enable_default(self):
308330
continue
309331
logger.setLevel(stdlogging.CRITICAL)
310332

333+
def before_enable_info(self):
334+
"""Logs status before enable Default."""
335+
self._logger.info(f"Enabling default logging.")
336+
self._logger.setLevel(stdlogging.INFO)
337+
for logger in all_loggers():
338+
if logger.name in self._primary_loggers:
339+
continue
340+
logger.setLevel(stdlogging.CRITICAL)
341+
311342
def after_enable_default(self):
312343
pass
313344

345+
def before_enable_warning(self):
346+
"""Logs status before enable Warning."""
347+
self._logger.info("Enabling warning.")
348+
self._stream_formatter.set_trace(True)
349+
for logger in all_loggers():
350+
logger.setLevel(stdlogging.WARNING)
351+
352+
def after_enable_warning(self):
353+
"""Logs status after enable Warning."""
354+
self._logger.info("Warning enabled.")
355+
314356
# Trace
315357
def before_enable_trace(self):
316358
"""Logs status before enable Trace."""
@@ -449,6 +491,25 @@ def set_trace(self, on: bool = True):
449491
if self.current_state_value == "Trace":
450492
self.disable_trace()
451493

494+
def set_warning(self, on: bool = True):
495+
"""Sets Warning state."""
496+
if on and not self.current_state_value == "Warning":
497+
self.enable_warning()
498+
elif not on:
499+
if self.current_state_value == "Warning":
500+
self.disable_warning()
501+
502+
def set_default(self):
503+
"""Sets Default state."""
504+
if not self.current_state_value == "Default":
505+
self.enable_default()
506+
507+
# as an option to be more obvious. `bittensor.logging.set_info()` is the same `bittensor.logging.set_default()`
508+
def set_info(self):
509+
"""Sets Default state."""
510+
if not self.current_state_value == "Default":
511+
self.enable_info()
512+
452513
def get_level(self) -> int:
453514
"""Returns Logging level."""
454515
return self._logger.level

bittensor/utils/deprecated.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
get_hash,
112112
)
113113
from bittensor.utils.balance import Balance as Balance # noqa: F401
114+
from bittensor.utils.btlogging import logging
114115
from bittensor.utils.mock.subtensor_mock import MockSubtensor as MockSubtensor # noqa: F401
115116
from bittensor.utils.subnets import SubnetsAPI # noqa: F401
116117

@@ -148,3 +149,38 @@
148149
# Makes the `bittensor.core.extrinsics` subpackage available as `bittensor.extrinsics` for backwards compatibility.
149150
extrinsics_subpackage = importlib.import_module("bittensor.core.extrinsics")
150151
sys.modules["bittensor.extrinsics"] = extrinsics_subpackage
152+
153+
154+
# Logging helpers.
155+
def trace(on: bool = True):
156+
"""
157+
Enables or disables trace logging.
158+
159+
Args:
160+
on (bool): If True, enables trace logging. If False, disables trace logging.
161+
"""
162+
logging.set_trace(on)
163+
164+
165+
def debug(on: bool = True):
166+
"""
167+
Enables or disables debug logging.
168+
169+
Args:
170+
on (bool): If True, enables debug logging. If False, disables debug logging.
171+
"""
172+
logging.set_debug(on)
173+
174+
175+
def warning(on: bool = True):
176+
"""
177+
Enables or disables warning logging.
178+
179+
Args:
180+
on (bool): If True, enables warning logging. If False, disables warning logging and sets default (INFO) level.
181+
"""
182+
logging.set_warning(on)
183+
184+
185+
# set Warning logging level for bittensor SDK
186+
warning()

0 commit comments

Comments
 (0)