nercone-modern 1.4.5__py3-none-any.whl → 1.5.0__py3-none-any.whl
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.
nercone_modern/logging.py
CHANGED
|
@@ -40,69 +40,68 @@ def is_higher_priority(level_a: str, level_b: str) -> bool:
|
|
|
40
40
|
raise ValueError(f"Unknown log level: {level_a} or {level_b}")
|
|
41
41
|
|
|
42
42
|
class ModernLogging:
|
|
43
|
-
def __init__(self, process_name: str, display_level: str = "INFO"):
|
|
43
|
+
def __init__(self, process_name: str = "App", display_level: str = "INFO", filepath: str | None = None):
|
|
44
44
|
self.process_name = process_name
|
|
45
45
|
self.display_level = display_level
|
|
46
|
-
|
|
46
|
+
self.filepath = filepath
|
|
47
47
|
global _max_proc_width
|
|
48
48
|
_max_proc_width = max(_max_proc_width, len(process_name))
|
|
49
49
|
|
|
50
|
-
def log(self, message: str = "",
|
|
51
|
-
if not is_higher_priority(
|
|
50
|
+
def log(self, message: str = "", level_text: str = "INFO", level_color: str | None = None):
|
|
51
|
+
if not is_higher_priority(level_text, self.display_level):
|
|
52
52
|
return
|
|
53
|
-
|
|
54
53
|
global _last_process, _last_level
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
show_level = show_proc or (level_text != _last_level)
|
|
58
|
-
|
|
59
|
-
if level_text == "DEBUG":
|
|
60
|
-
color = 'gray'
|
|
61
|
-
elif level_text == "INFO":
|
|
62
|
-
color = 'blue'
|
|
63
|
-
elif level_text == "WARN":
|
|
64
|
-
color = 'yellow'
|
|
65
|
-
elif level_text == "ERROR":
|
|
66
|
-
color = 'red'
|
|
67
|
-
elif level_text == "CRITICAL":
|
|
68
|
-
color = 'red'
|
|
69
|
-
else:
|
|
70
|
-
color = 'blue'
|
|
71
|
-
|
|
72
|
-
print(self._make(message, level_text, color, show_proc, show_level))
|
|
73
|
-
|
|
54
|
+
log_line = self.make(message=message, level_text=level_text, level_color=level_color)
|
|
55
|
+
print(log_line)
|
|
74
56
|
_last_process = self.process_name
|
|
75
|
-
_last_level = level_text
|
|
57
|
+
_last_level = normalize_level(level_text.strip().upper())
|
|
58
|
+
if self.filepath:
|
|
59
|
+
with open(self.filepath, "a") as f:
|
|
60
|
+
f.write(f"{log_line}\n")
|
|
76
61
|
|
|
77
|
-
def prompt(self, message: str = "",
|
|
78
|
-
if not is_higher_priority(
|
|
62
|
+
def prompt(self, message: str = "", level_text: str = "INFO", level_color: str | None = None, ignore_kbdinterrupt: bool = True) -> str:
|
|
63
|
+
if not is_higher_priority(level_text, self.display_level):
|
|
79
64
|
return
|
|
80
|
-
|
|
81
65
|
global _last_process, _last_level
|
|
82
|
-
|
|
66
|
+
log_line = self.make(message=message, level_text=level_text, level_color=level_color)
|
|
67
|
+
print(log_line, end="")
|
|
68
|
+
_last_process = self.process_name
|
|
69
|
+
_last_level = normalize_level(level_text.strip().upper())
|
|
70
|
+
answer = ""
|
|
71
|
+
try:
|
|
72
|
+
answer = input()
|
|
73
|
+
except KeyboardInterrupt:
|
|
74
|
+
if ignore_kbdinterrupt:
|
|
75
|
+
print()
|
|
76
|
+
else:
|
|
77
|
+
raise
|
|
78
|
+
if self.filepath:
|
|
79
|
+
with open(self.filepath, "a") as f:
|
|
80
|
+
f.write(f"{log_line}{answer}\n")
|
|
81
|
+
return answer
|
|
82
|
+
|
|
83
|
+
def make(self, message: str = "", level_text: str = "INFO", level_color: str | None = None):
|
|
84
|
+
level_text = normalize_level(level_text.strip().upper())
|
|
83
85
|
show_proc = (self.process_name != _last_process)
|
|
84
86
|
show_level = show_proc or (level_text != _last_level)
|
|
85
87
|
|
|
86
|
-
if
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return input()
|
|
104
|
-
|
|
105
|
-
def _make(self, message: str, level_text: str, color: str, show_proc: bool, show_level: bool):
|
|
88
|
+
if not level_color:
|
|
89
|
+
if level_text == "DEBUG":
|
|
90
|
+
level_color = 'gray'
|
|
91
|
+
elif level_text == "INFO":
|
|
92
|
+
level_color = 'blue'
|
|
93
|
+
elif level_text == "WARN":
|
|
94
|
+
level_color = 'yellow'
|
|
95
|
+
elif level_text == "ERROR":
|
|
96
|
+
level_color = 'red'
|
|
97
|
+
elif level_text == "CRITICAL":
|
|
98
|
+
level_color = 'red'
|
|
99
|
+
else:
|
|
100
|
+
level_color = 'blue'
|
|
101
|
+
|
|
102
|
+
return self._make(message, level_text, level_color, show_proc, show_level)
|
|
103
|
+
|
|
104
|
+
def _make(self, message: str, level_text: str, level_color: str, show_proc: bool, show_level: bool):
|
|
106
105
|
global _max_proc_width
|
|
107
106
|
level_width = max(MAX_LOG_LEVEL_WIDTH, len(level_text))
|
|
108
107
|
|
|
@@ -110,9 +109,9 @@ class ModernLogging:
|
|
|
110
109
|
proc_part = proc_part.ljust(_max_proc_width) if proc_part else " " * _max_proc_width
|
|
111
110
|
|
|
112
111
|
if show_level:
|
|
113
|
-
level_part = f"{self._color(
|
|
112
|
+
level_part = f"{self._color(level_color)}{level_text.ljust(level_width)} |{self._color('reset')}"
|
|
114
113
|
else:
|
|
115
|
-
level_part = (" " * level_width) + f"{self._color(
|
|
114
|
+
level_part = (" " * level_width) + f"{self._color(level_color)} |{self._color('reset')}"
|
|
116
115
|
|
|
117
116
|
return f"{proc_part} {level_part} {str(message)}"
|
|
118
117
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
nercone_modern/__init__.py,sha256=ArF3T8FdWIhwGcL4MfYcHqMse3n5gjuyzbLNlcqRcxs,443
|
|
2
2
|
nercone_modern/__main__.py,sha256=wKQnrGpTKemaaMv1oow_KKQFfPqxzhkz4KAhWBjVcYg,1957
|
|
3
3
|
nercone_modern/color.py,sha256=sy7f0Fe07PZWNfM1AOt7HeuhF7uGK2_IuZHEckwgxc4,1328
|
|
4
|
-
nercone_modern/logging.py,sha256=
|
|
4
|
+
nercone_modern/logging.py,sha256=javSGxKRnbJIYjh1deIuhcI7jOSAZud4Wdo0x0S5yOM,5489
|
|
5
5
|
nercone_modern/progressbar.py,sha256=bzlGg0dSj88eli2lM0cI4xTw2FNJqlJb352jdtJbsWQ,8088
|
|
6
6
|
nercone_modern/text.py,sha256=eGxGQOJ3b-783ocLibkG62cOcYD4HLG_3diA52tU8jI,1031
|
|
7
|
-
nercone_modern-1.
|
|
8
|
-
nercone_modern-1.
|
|
9
|
-
nercone_modern-1.
|
|
7
|
+
nercone_modern-1.5.0.dist-info/WHEEL,sha256=DpNsHFUm_gffZe1FgzmqwuqiuPC6Y-uBCzibcJcdupM,78
|
|
8
|
+
nercone_modern-1.5.0.dist-info/METADATA,sha256=d5dS4gyv-nl5SJZknqjZgGKdjJ2VyzQ72HnATOIFwtA,2472
|
|
9
|
+
nercone_modern-1.5.0.dist-info/RECORD,,
|