Skip to content

Commit

Permalink
move logging setup from b2sdk module to b2sdk._v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Mar 29, 2024
1 parent e26d007 commit 27b8593
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
13 changes: 0 additions & 13 deletions b2sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@
######################################################################
from __future__ import annotations

# Set default logging handler to avoid "No handler found" warnings.
import logging

logging.getLogger(__name__).addHandler(logging.NullHandler())


class UrllibWarningFilter:
def filter(self, record):
return record.msg != "Connection pool is full, discarding connection: %s"


logging.getLogger('urllib3.connectionpool').addFilter(UrllibWarningFilter())

import b2sdk.version # noqa: E402
__version__ = b2sdk.version.VERSION
assert __version__ # PEP-0396
13 changes: 13 additions & 0 deletions b2sdk/_v3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
######################################################################
from __future__ import annotations

# Set default logging handler to avoid "No handler found" warnings.
import logging

logging.getLogger("b2sdk").addHandler(logging.NullHandler())


class UrllibWarningFilter:
def filter(self, record):
return record.msg != "Connection pool is full, discarding connection: %s"


logging.getLogger('urllib3.connectionpool').addFilter(UrllibWarningFilter())

# this file maps the external interface into internal interface
# it will come handy if we ever need to move something

Expand Down
2 changes: 2 additions & 0 deletions changelog.d/+logging.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Move logging setup and `UrllibWarningFilter` class from `b2sdk.__init__.py` to `b2sdk._v3` (and thus `b2sdk.v2` & `b2sdk.v1`).
This will allow us to remove/change it in new apiver releases without the need to change the major semver version.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ target-version = "py37"

[tool.ruff.per-file-ignores]
"__init__.py" = ["I", "F401"]
"b2sdk/_v3/__init__.py" = ["E402"]
"b2sdk/v*/**" = ["I", "F403", "F405"]
"b2sdk/_v*/**" = ["I", "F403", "F405"]
"test/**" = ["D", "F403", "F405"]
Expand Down

0 comments on commit 27b8593

Please sign in to comment.