Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move root logger config to CLI module #28

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move logger config to CLI module
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 committed Nov 18, 2021
commit c843f0875b5c4a4bddf3eacb11a997fd28456584
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"))
avaldebe marked this conversation as resolved.
Show resolved Hide resolved


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