drifTech-lib 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of drifTech-lib might be problematic. Click here for more details.
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/PKG-INFO +1 -1
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/pyproject.toml +1 -1
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/pyproject.toml.orig +1 -1
- driftech_lib-0.4.0/src/driftech_lib/logging.py +123 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/LICENSE +0 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/README.md +0 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/src/driftech_lib/__init__.py +0 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/src/driftech_lib/db.py +0 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/src/driftech_lib/ipc/__init__.py +0 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/src/driftech_lib/ipc/client.py +0 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/src/driftech_lib/ipc/server.py +0 -0
- {driftech_lib-0.3.0 → driftech_lib-0.4.0}/src/driftech_lib/jsonIO.py +0 -0
|
@@ -8,7 +8,7 @@ build-backend = "uv_build"
|
|
|
8
8
|
|
|
9
9
|
[project]
|
|
10
10
|
name = "drifTech-lib"
|
|
11
|
-
version = "0.
|
|
11
|
+
version = "0.4.0"
|
|
12
12
|
authors = [{name = "driftbluestone", email = "driftbluestone@gmail.com"}]
|
|
13
13
|
description = "Common files/functions across most drifTech software"
|
|
14
14
|
readme = "README.md"
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import sys, time, inspect
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
|
|
5
|
+
default_LoSs = {
|
|
6
|
+
"UNSET": 0,
|
|
7
|
+
"DEBUG": 10,
|
|
8
|
+
"INFO": 20,
|
|
9
|
+
"WARN": 30,
|
|
10
|
+
"ERROR": 40,
|
|
11
|
+
"FATAL": 50
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class Logger:
|
|
15
|
+
def __init__(self,
|
|
16
|
+
name: str,
|
|
17
|
+
file: str | Path = None,
|
|
18
|
+
reset_file_on_restart: bool = True,
|
|
19
|
+
console = sys.stdout,
|
|
20
|
+
min_console_severity: int = 0,
|
|
21
|
+
min_file_severity: int = 0,
|
|
22
|
+
time_format: str = "%Y-%m-%d %H:%M:%S",
|
|
23
|
+
LoSs: dict[str, int] = default_LoSs,
|
|
24
|
+
):
|
|
25
|
+
self.reset_file_on_restart = reset_file_on_restart
|
|
26
|
+
self.name = name
|
|
27
|
+
self.console = console
|
|
28
|
+
self.file = file
|
|
29
|
+
self.time_format = time_format
|
|
30
|
+
self.LoSs = LoSs
|
|
31
|
+
self.RLoSs = {v: k for k, v in LoSs.items()}
|
|
32
|
+
self.min_console_severity = min_console_severity
|
|
33
|
+
self.min_file_severity = min_file_severity
|
|
34
|
+
|
|
35
|
+
if reset_file_on_restart and file:
|
|
36
|
+
with open(file, "w") as f:
|
|
37
|
+
f.write("")
|
|
38
|
+
|
|
39
|
+
def add_LoS(self, name: str, severity: int):
|
|
40
|
+
self.LoSs[name] = severity
|
|
41
|
+
self.RLoSs[severity] = name
|
|
42
|
+
|
|
43
|
+
def _premessage(self, severity):
|
|
44
|
+
tm = time.strftime(self.time_format)
|
|
45
|
+
return f"{tm} [{self.name}/{self.RLoSs[severity]}]: "
|
|
46
|
+
|
|
47
|
+
async def alog(self, severity: int, content: str, secondary: Callable = None, kwarg: str = None):
|
|
48
|
+
"""Async compatible implementation of `log`"""
|
|
49
|
+
if isinstance(severity, str):
|
|
50
|
+
severity = self.LoSs[severity]
|
|
51
|
+
|
|
52
|
+
content = f"{self._premessage(severity)}{content}\n"
|
|
53
|
+
|
|
54
|
+
if secondary and inspect.iscoroutinefunction(secondary):
|
|
55
|
+
if kwarg:
|
|
56
|
+
await secondary(**{kwarg: content})
|
|
57
|
+
else:
|
|
58
|
+
await secondary(content)
|
|
59
|
+
elif secondary:
|
|
60
|
+
if kwarg:
|
|
61
|
+
secondary(**{kwarg: content})
|
|
62
|
+
else:
|
|
63
|
+
secondary(content)
|
|
64
|
+
|
|
65
|
+
if (severity >= self.min_console_severity) and (self.console):
|
|
66
|
+
self.console.write(content)
|
|
67
|
+
if inspect.iscoroutinefunction(self.console.flush):
|
|
68
|
+
await self.console.flush()
|
|
69
|
+
else:
|
|
70
|
+
self.console.flush()
|
|
71
|
+
|
|
72
|
+
if (severity >= self.min_file_severity) and (self.file):
|
|
73
|
+
with open(self.file, "a") as file:
|
|
74
|
+
file.write(content)
|
|
75
|
+
|
|
76
|
+
def log(self, severity: int, content: str, secondary: Callable = None, kwarg: str = None):
|
|
77
|
+
if isinstance(severity, str):
|
|
78
|
+
severity = self.LoSs[severity]
|
|
79
|
+
|
|
80
|
+
content = f"{self._premessage(severity)}{content}\n"
|
|
81
|
+
|
|
82
|
+
if secondary:
|
|
83
|
+
if kwarg:
|
|
84
|
+
secondary(**{kwarg: content})
|
|
85
|
+
else:
|
|
86
|
+
secondary(content)
|
|
87
|
+
if (severity >= self.min_console_severity) and (self.console):
|
|
88
|
+
self.console.write(content)
|
|
89
|
+
self.console.flush()
|
|
90
|
+
|
|
91
|
+
if (severity >= self.min_file_severity) and (self.file):
|
|
92
|
+
with open(self.file, "a") as file:
|
|
93
|
+
file.write(content)
|
|
94
|
+
|
|
95
|
+
def debug(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
96
|
+
self.log(self.LoSs["DEBUG"], content, secondary, kwarg)
|
|
97
|
+
|
|
98
|
+
def info(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
99
|
+
self.log(self.LoSs["INFO"], content, secondary, kwarg)
|
|
100
|
+
|
|
101
|
+
def warn(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
102
|
+
self.log(self.LoSs["WARN"], content, secondary, kwarg)
|
|
103
|
+
|
|
104
|
+
def error(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
105
|
+
self.log(self.LoSs["ERROR"], content, secondary, kwarg)
|
|
106
|
+
|
|
107
|
+
def fatal(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
108
|
+
self.log(self.LoSs["FATAL"], content, secondary, kwarg)
|
|
109
|
+
|
|
110
|
+
async def adebug(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
111
|
+
await self.alog(self.LoSs["DEBUG"], content, secondary, kwarg)
|
|
112
|
+
|
|
113
|
+
async def ainfo(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
114
|
+
await self.alog(self.LoSs["INFO"], content, secondary, kwarg)
|
|
115
|
+
|
|
116
|
+
async def awarn(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
117
|
+
await self.alog(self.LoSs["WARN"], content, secondary, kwarg)
|
|
118
|
+
|
|
119
|
+
async def aerror(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
120
|
+
await self.alog(self.LoSs["ERROR"], content, secondary, kwarg)
|
|
121
|
+
|
|
122
|
+
async def afatal(self, content: str, secondary: Callable = None, kwarg: str = None):
|
|
123
|
+
await self.alog(self.LoSs["FATAL"], content, secondary, kwarg)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|