Skip to content

Commit

Permalink
Move logger config to CLI module
Browse files Browse the repository at this point in the history
Previously we configured the root logger in the PMS package itself,
which would mean any code using the package as a library would get
the logging config as a side effect.

Rather than configure the root logger, which should be left to the
toplevel program, this re-scopes how we set the config to apply to
just the specific logger for the package.
  • Loading branch information
benthorner authored and avaldebe committed Nov 19, 2021
1 parent f5613db commit ecd0c9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/pms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import logging
import os

logging.basicConfig(level=os.getenv("LEVEL", "WARNING"))
logger = logging.getLogger(__name__)


Expand Down
8 changes: 6 additions & 2 deletions src/pms/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging
import os
import sys
from datetime import datetime
from enum import Enum
Expand Down Expand Up @@ -25,6 +27,9 @@
main.command(name=ep.name)(ep.load())


logging.basicConfig(level=os.getenv("LEVEL", "WARNING"))


def version_callback(value: bool): # pragma: no cover
if not value:
return
Expand All @@ -45,8 +50,7 @@ def callback(
version: Optional[bool] = Option(None, "--version", "-V", callback=version_callback),
):
"""Read serial sensor"""
if debug: # pragma: no cover
logger.setLevel("DEBUG")
logger.setLevel("DEBUG" if debug else os.getenv("LEVEL", "WARNING"))
ctx.obj = {"reader": SensorReader(model, port, seconds, samples)}


Expand Down

0 comments on commit ecd0c9d

Please sign in to comment.