Skip to content

Commit 1f25473

Browse files
committed
Use dictConfig
1 parent ab165c3 commit 1f25473

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

twine/cli.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import argparse
15-
import logging
15+
import logging.config
1616
from typing import Any, List, Tuple
1717

1818
import importlib_metadata
@@ -48,20 +48,26 @@
4848

4949

5050
def configure_logging() -> None:
51-
root_logger = logging.getLogger("twine")
52-
53-
# This prevents failures test_main.py due to capsys not being cleared.
54-
# TODO: Use dictConfig() instead?
55-
for handler in root_logger.handlers:
56-
root_logger.removeHandler(handler)
57-
58-
root_logger.addHandler(
59-
rich.logging.RichHandler(
60-
console=console,
61-
show_time=False,
62-
show_path=False,
63-
highlighter=rich.highlighter.NullHighlighter(),
64-
)
51+
# Using dictConfig to override existing loggers, which prevents failures in
52+
# test_main.py due to capsys not being cleared.
53+
logging.config.dictConfig(
54+
{
55+
"version": 1,
56+
"handlers": {
57+
"console": {
58+
"class": "rich.logging.RichHandler",
59+
"console": console,
60+
"show_time": False,
61+
"show_path": False,
62+
"highlighter": rich.highlighter.NullHighlighter(),
63+
}
64+
},
65+
"loggers": {
66+
"twine": {
67+
"handlers": ["console"],
68+
},
69+
},
70+
}
6571
)
6672

6773

twine/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def verbose(self) -> bool:
149149
def verbose(self, verbose: bool) -> None:
150150
"""Initialize a logger based on the --verbose option."""
151151
self._verbose = verbose
152-
root_logger = logging.getLogger("twine")
153-
root_logger.setLevel(logging.INFO if verbose else logging.WARNING)
152+
twine_logger = logging.getLogger("twine")
153+
twine_logger.setLevel(logging.INFO if verbose else logging.WARNING)
154154

155155
@staticmethod
156156
def register_argparse_arguments(parser: argparse.ArgumentParser) -> None:

0 commit comments

Comments
 (0)