Skip to content

Commit 4735981

Browse files
committed
Merge branch 'feature/logging' into develop
2 parents 522be5c + 3a59004 commit 4735981

File tree

7 files changed

+82
-3
lines changed

7 files changed

+82
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
__pycache__
22
*.egg-info
3+
*.log
34
.coverage
45
.mypy_cache
6+
.pypirc
57
.pytest_cache
68
.ruff_cache
7-
.pypirc
89
.venv
910
dist

src/pywaveshare/boards/sim868/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def __processData(self):
320320
rawData = match[0][1].split(",")
321321
self.__GPRSIPaddress = rawData[2].replace('"', "")
322322

323-
if self.__GPRSIPaddress != "0.0.0.0": # nosec
323+
if self.__GPRSIPaddress != "0.0.0.0": # nosec
324324
self.__GPRSready = True
325325
else:
326326
self.__GPRSready = False

src/pywaveshare/boards/sim868/client.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
class Client:
5+
logger = config.get_logger("client")
6+
57
def __init__(self, config: config.Config) -> None:
68
self.config = config
79
self.worker = worker.Worker(self.config)

src/pywaveshare/boards/sim868/config.py

+69
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,72 @@
1+
import json
2+
import logging
3+
import logging.config
4+
import time
5+
6+
LOGGING_CONFIG = {
7+
"version": 1,
8+
"formatters": {
9+
"txt": {
10+
"format": "[%(asctime)s.%(msecs)03d][%(levelname)s]: %(message)s",
11+
"datefmt": "%Y-%m-%dT%H:%M:%S",
12+
},
13+
"jsonl": {
14+
"format": json.dumps(
15+
{
16+
"timestamp": "%(asctime)s.%(msecs)03d",
17+
"process": "%(process)d",
18+
"thread": "%(thread)d",
19+
"logger": "%(name)s",
20+
"level": "%(levelname)s",
21+
"source": "%(pathname)s:%(lineno)d",
22+
"message": "%(message)s",
23+
}
24+
),
25+
"datefmt": "%Y-%m-%dT%H:%M:%S",
26+
},
27+
},
28+
"filters": {},
29+
"handlers": {
30+
"file": {
31+
"class": "logging.FileHandler",
32+
"filename": "event.log",
33+
"formatter": "jsonl",
34+
"level": "DEBUG",
35+
"filters": [],
36+
},
37+
"stream": {
38+
"class": "logging.StreamHandler",
39+
"formatter": "txt",
40+
"level": "DEBUG",
41+
"filters": [],
42+
},
43+
},
44+
"loggers": {
45+
"client": {
46+
"handlers": ["file", "stream"],
47+
"level": "DEBUG",
48+
"propagate": True,
49+
},
50+
"worker": {
51+
"handlers": ["file", "stream"],
52+
"level": "DEBUG",
53+
"propagate": True,
54+
},
55+
"protocol": {
56+
"handlers": ["file", "stream"],
57+
"level": "DEBUG",
58+
"propagate": True,
59+
},
60+
},
61+
}
62+
logging.Formatter.converter = time.gmtime
63+
logging.config.dictConfig(LOGGING_CONFIG)
64+
65+
66+
def get_logger(id: str) -> logging.Logger:
67+
return logging.getLogger(id)
68+
69+
170
class Config:
271
def __init__(self, serial_port: str, baud_rate: int, encoding: str) -> None:
372
self.serial_port = serial_port

src/pywaveshare/boards/sim868/itc.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import queue
24
import threading
35

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import abc
2+
import typing
23

34

45
class SupportedProtocol(abc.ABC):
5-
pass
6+
NAME: typing.Optional[str] = None
7+
8+
RESPONSE_PATTERN = r""

src/pywaveshare/boards/sim868/worker.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55

66
class Worker(threading.Thread):
7+
logger = config.get_logger("worker")
8+
79
def __init__(self, config: config.Config) -> None:
810
super().__init__()
911

0 commit comments

Comments
 (0)