Skip to content

Commit

Permalink
Use dictConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrutledge committed Jan 23, 2022
1 parent ab165c3 commit 1f25473
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
36 changes: 21 additions & 15 deletions twine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import logging
import logging.config
from typing import Any, List, Tuple

import importlib_metadata
Expand Down Expand Up @@ -48,20 +48,26 @@


def configure_logging() -> None:
root_logger = logging.getLogger("twine")

# This prevents failures test_main.py due to capsys not being cleared.
# TODO: Use dictConfig() instead?
for handler in root_logger.handlers:
root_logger.removeHandler(handler)

root_logger.addHandler(
rich.logging.RichHandler(
console=console,
show_time=False,
show_path=False,
highlighter=rich.highlighter.NullHighlighter(),
)
# Using dictConfig to override existing loggers, which prevents failures in
# test_main.py due to capsys not being cleared.
logging.config.dictConfig(
{
"version": 1,
"handlers": {
"console": {
"class": "rich.logging.RichHandler",
"console": console,
"show_time": False,
"show_path": False,
"highlighter": rich.highlighter.NullHighlighter(),
}
},
"loggers": {
"twine": {
"handlers": ["console"],
},
},
}
)


Expand Down
4 changes: 2 additions & 2 deletions twine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def verbose(self) -> bool:
def verbose(self, verbose: bool) -> None:
"""Initialize a logger based on the --verbose option."""
self._verbose = verbose
root_logger = logging.getLogger("twine")
root_logger.setLevel(logging.INFO if verbose else logging.WARNING)
twine_logger = logging.getLogger("twine")
twine_logger.setLevel(logging.INFO if verbose else logging.WARNING)

@staticmethod
def register_argparse_arguments(parser: argparse.ArgumentParser) -> None:
Expand Down

0 comments on commit 1f25473

Please sign in to comment.