Skip to content

Commit

Permalink
Merge branch 'feature/logging' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
acmacunlay committed Oct 8, 2024
2 parents 522be5c + 3a59004 commit 4735981
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
__pycache__
*.egg-info
*.log
.coverage
.mypy_cache
.pypirc
.pytest_cache
.ruff_cache
.pypirc
.venv
dist
2 changes: 1 addition & 1 deletion src/pywaveshare/boards/sim868/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def __processData(self):
rawData = match[0][1].split(",")
self.__GPRSIPaddress = rawData[2].replace('"', "")

if self.__GPRSIPaddress != "0.0.0.0": # nosec
if self.__GPRSIPaddress != "0.0.0.0": # nosec
self.__GPRSready = True
else:
self.__GPRSready = False
Expand Down
2 changes: 2 additions & 0 deletions src/pywaveshare/boards/sim868/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


class Client:
logger = config.get_logger("client")

def __init__(self, config: config.Config) -> None:
self.config = config
self.worker = worker.Worker(self.config)
Expand Down
69 changes: 69 additions & 0 deletions src/pywaveshare/boards/sim868/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
import json
import logging
import logging.config
import time

LOGGING_CONFIG = {
"version": 1,
"formatters": {
"txt": {
"format": "[%(asctime)s.%(msecs)03d][%(levelname)s]: %(message)s",
"datefmt": "%Y-%m-%dT%H:%M:%S",
},
"jsonl": {
"format": json.dumps(
{
"timestamp": "%(asctime)s.%(msecs)03d",
"process": "%(process)d",
"thread": "%(thread)d",
"logger": "%(name)s",
"level": "%(levelname)s",
"source": "%(pathname)s:%(lineno)d",
"message": "%(message)s",
}
),
"datefmt": "%Y-%m-%dT%H:%M:%S",
},
},
"filters": {},
"handlers": {
"file": {
"class": "logging.FileHandler",
"filename": "event.log",
"formatter": "jsonl",
"level": "DEBUG",
"filters": [],
},
"stream": {
"class": "logging.StreamHandler",
"formatter": "txt",
"level": "DEBUG",
"filters": [],
},
},
"loggers": {
"client": {
"handlers": ["file", "stream"],
"level": "DEBUG",
"propagate": True,
},
"worker": {
"handlers": ["file", "stream"],
"level": "DEBUG",
"propagate": True,
},
"protocol": {
"handlers": ["file", "stream"],
"level": "DEBUG",
"propagate": True,
},
},
}
logging.Formatter.converter = time.gmtime
logging.config.dictConfig(LOGGING_CONFIG)


def get_logger(id: str) -> logging.Logger:
return logging.getLogger(id)


class Config:
def __init__(self, serial_port: str, baud_rate: int, encoding: str) -> None:
self.serial_port = serial_port
Expand Down
2 changes: 2 additions & 0 deletions src/pywaveshare/boards/sim868/itc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import queue
import threading

Expand Down
5 changes: 4 additions & 1 deletion src/pywaveshare/boards/sim868/protocols.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import abc
import typing


class SupportedProtocol(abc.ABC):
pass
NAME: typing.Optional[str] = None

RESPONSE_PATTERN = r""
2 changes: 2 additions & 0 deletions src/pywaveshare/boards/sim868/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


class Worker(threading.Thread):
logger = config.get_logger("worker")

def __init__(self, config: config.Config) -> None:
super().__init__()

Expand Down

0 comments on commit 4735981

Please sign in to comment.