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 all commits
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
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
12 changes: 10 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 Expand Up @@ -127,3 +131,7 @@ def csv(
csv.write("time,sensor,hex\n")
for raw in reader(raw=True):
csv.write(f"{raw.time},{sensor_name},{raw.hex}\n")


if __name__ == "__main__": # pragma: no cover
main()