MapleX 3.0.0.dev2__py3-none-any.whl → 3.0.0.dev4__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.
- maplex/__init__.py +4 -3
- maplex/{mapleJson.py → json.py} +30 -9
- maplex/mapleLogger.py +167 -116
- {maplex-3.0.0.dev2.dist-info → maplex-3.0.0.dev4.dist-info}/METADATA +16 -8
- maplex-3.0.0.dev4.dist-info/RECORD +12 -0
- maplex-3.0.0.dev2.dist-info/RECORD +0 -12
- {maplex-3.0.0.dev2.dist-info → maplex-3.0.0.dev4.dist-info}/WHEEL +0 -0
- {maplex-3.0.0.dev2.dist-info → maplex-3.0.0.dev4.dist-info}/licenses/LICENSE +0 -0
- {maplex-3.0.0.dev2.dist-info → maplex-3.0.0.dev4.dist-info}/top_level.txt +0 -0
maplex/__init__.py
CHANGED
|
@@ -4,8 +4,8 @@ Logger: A simple logging utility for tracking events and debugging.
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from .mapleColors import ConsoleColors
|
|
7
|
-
from .
|
|
8
|
-
from .mapleLogger import Logger, getLogger
|
|
7
|
+
from .json import MapleJson
|
|
8
|
+
from .mapleLogger import Logger, getLogger, getDailyLogger
|
|
9
9
|
from .mapleExceptions import (
|
|
10
10
|
InvalidMapleFileFormatException,
|
|
11
11
|
KeyEmptyException,
|
|
@@ -26,6 +26,7 @@ from .utils import winHide, winUnHide
|
|
|
26
26
|
|
|
27
27
|
__all__ = [
|
|
28
28
|
'ConsoleColors',
|
|
29
|
+
'getDailyLogger',
|
|
29
30
|
'getLogger',
|
|
30
31
|
'InvalidMapleFileFormatException',
|
|
31
32
|
'KeyEmptyException',
|
|
@@ -47,6 +48,6 @@ __all__ = [
|
|
|
47
48
|
'winUnHide'
|
|
48
49
|
]
|
|
49
50
|
|
|
50
|
-
__version__ = "3.0.0.
|
|
51
|
+
__version__ = "3.0.0.dev4"
|
|
51
52
|
__author__ = "Ryuji Hazama"
|
|
52
53
|
__license__ = "MIT"
|
maplex/{mapleJson.py → json.py}
RENAMED
|
@@ -6,12 +6,19 @@ from . import mapleExceptions as mExc
|
|
|
6
6
|
|
|
7
7
|
class MapleJson:
|
|
8
8
|
|
|
9
|
-
def __init__(self,
|
|
9
|
+
def __init__(self,
|
|
10
|
+
filePath: str,
|
|
11
|
+
fileEncoding: str = 'utf-8',
|
|
12
|
+
indent: int = 4,
|
|
13
|
+
ensureAscii: bool = False,
|
|
14
|
+
encrypt: bool = False,
|
|
15
|
+
key: bytes = None
|
|
16
|
+
) -> None:
|
|
10
17
|
|
|
11
18
|
self.filePath = filePath
|
|
12
19
|
self.fileEncoding = fileEncoding
|
|
13
20
|
self.indent = indent
|
|
14
|
-
self.
|
|
21
|
+
self.ensureAscii = ensureAscii
|
|
15
22
|
self.encrypt = encrypt
|
|
16
23
|
self.key = key
|
|
17
24
|
self.fernet = Fernet(key) if encrypt and key else None
|
|
@@ -46,11 +53,11 @@ class MapleJson:
|
|
|
46
53
|
|
|
47
54
|
def getEnsureAscii(self) -> bool:
|
|
48
55
|
|
|
49
|
-
return self.
|
|
56
|
+
return self.ensureAscii
|
|
50
57
|
|
|
51
|
-
def setEnsureAscii(self,
|
|
58
|
+
def setEnsureAscii(self, ensureAscii: bool) -> None:
|
|
52
59
|
|
|
53
|
-
self.
|
|
60
|
+
self.ensureAscii = ensureAscii
|
|
54
61
|
|
|
55
62
|
def isEncrypted(self) -> bool:
|
|
56
63
|
|
|
@@ -80,7 +87,7 @@ class MapleJson:
|
|
|
80
87
|
#####################
|
|
81
88
|
# Basic File Operations
|
|
82
89
|
|
|
83
|
-
def read(self) -> dict:
|
|
90
|
+
def read(self, *keys) -> dict | None:
|
|
84
91
|
|
|
85
92
|
try:
|
|
86
93
|
|
|
@@ -91,12 +98,26 @@ class MapleJson:
|
|
|
91
98
|
if self.encrypt and self.fernet:
|
|
92
99
|
|
|
93
100
|
decryptedData = self.fernet.decrypt(data)
|
|
94
|
-
|
|
101
|
+
jsonData = json.loads(decryptedData.decode(self.fileEncoding))
|
|
95
102
|
|
|
96
103
|
else:
|
|
97
104
|
|
|
98
|
-
|
|
105
|
+
jsonData = json.loads(data.decode(self.fileEncoding))
|
|
99
106
|
|
|
107
|
+
# Navigate through keys if provided
|
|
108
|
+
|
|
109
|
+
if keys:
|
|
110
|
+
|
|
111
|
+
for jsonKey in keys:
|
|
112
|
+
|
|
113
|
+
if jsonData is None:
|
|
114
|
+
|
|
115
|
+
return None
|
|
116
|
+
|
|
117
|
+
jsonData = jsonData.get(jsonKey, None)
|
|
118
|
+
|
|
119
|
+
return jsonData
|
|
120
|
+
|
|
100
121
|
except FileNotFoundError:
|
|
101
122
|
|
|
102
123
|
raise mExc.MapleFileNotFoundException(self.filePath)
|
|
@@ -113,7 +134,7 @@ class MapleJson:
|
|
|
113
134
|
|
|
114
135
|
raise mExc.MapleTypeException(self.filePath, "Data to write must be a dictionary")
|
|
115
136
|
|
|
116
|
-
jsonData = json.dumps(data, indent=self.indent, ensure_ascii=self.
|
|
137
|
+
jsonData = json.dumps(data, indent=self.indent, ensure_ascii=self.ensureAscii).encode(self.fileEncoding)
|
|
117
138
|
|
|
118
139
|
if self.encrypt and self.fernet:
|
|
119
140
|
|
maplex/mapleLogger.py
CHANGED
|
@@ -6,7 +6,7 @@ import sys
|
|
|
6
6
|
import traceback
|
|
7
7
|
from enum import IntEnum
|
|
8
8
|
from typing import Literal
|
|
9
|
-
from .
|
|
9
|
+
from .json import MapleJson
|
|
10
10
|
from .mapleColors import ConsoleColors
|
|
11
11
|
from .mapleExceptions import *
|
|
12
12
|
|
|
@@ -38,18 +38,51 @@ class Logger:
|
|
|
38
38
|
self.fileMode = "append" if fileMode is None else fileMode
|
|
39
39
|
self.encoding = encoding
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
try:
|
|
42
|
+
|
|
43
|
+
# Check the OS (Windows 10 or older cannot change the console color)
|
|
44
|
+
|
|
45
|
+
if hasattr(sys, "getwindowsversion") and sys.getwindowsversion().build < 22000:
|
|
46
|
+
|
|
47
|
+
self.consoleColors = ConsoleColors(Black="", Red="", Green="", Yellow="", Blue="", Magenta="", LightBlue="", White="",
|
|
48
|
+
bgBlack="", bgRed="", bgGreen="", bgYellow="", bgBlue="", bgMagenta="", bgLightBlue="", bgWhite="",
|
|
49
|
+
bBlack="", bRed="", bGreen="", bYellow="", bBlue="", bMagenta="", bLightBlue="", bWhite="",
|
|
50
|
+
Bold="", Underline="", Reversed="", Reset="")
|
|
51
|
+
|
|
52
|
+
logConfInstance = self.__checkConfigFile(configFile)
|
|
53
|
+
self.__checkOutputDirectory(workingDirectory)
|
|
54
|
+
self.__setLogFileName(self.fileMode)
|
|
55
|
+
self.__setFuncName(kwargs.get("getLogger", False), func)
|
|
56
|
+
self.__setLogFileSize(maxLogSize)
|
|
57
|
+
self.__setOutputLogLevels(cmdLogLevel, fileLogLevel)
|
|
58
|
+
self.__setFileEncoding(encoding)
|
|
59
|
+
self.__saveLogSettings(logConfInstance)
|
|
60
|
+
|
|
61
|
+
except Exception as ex:
|
|
62
|
+
|
|
63
|
+
print(f"{self.consoleColors.Red}Error initializing logger: {ex}{self.consoleColors.Reset}")
|
|
64
|
+
raise MapleLoggerException(f"Error initializing logger: {ex}") from ex
|
|
42
65
|
|
|
43
|
-
|
|
66
|
+
#
|
|
67
|
+
#####################
|
|
68
|
+
# Set log level enum
|
|
69
|
+
|
|
70
|
+
class LogLevel(IntEnum):
|
|
71
|
+
|
|
72
|
+
TRACE = 0
|
|
73
|
+
DEBUG = 1
|
|
74
|
+
INFO = 2
|
|
75
|
+
WARN = 3
|
|
76
|
+
ERROR = 4
|
|
77
|
+
FATAL = 5
|
|
78
|
+
NONE = 6
|
|
44
79
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
bBlack="", bRed="", bGreen="", bYellow="", bBlue="", bMagenta="", bLightBlue="", bWhite="",
|
|
48
|
-
Bold="", Underline="", Reversed="", Reset="")
|
|
80
|
+
###########################################
|
|
81
|
+
# Special Methods for Class Initialization
|
|
49
82
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
83
|
+
def __checkConfigFile(self, configFile: str) -> MapleJson | None:
|
|
84
|
+
|
|
85
|
+
'''Check logger config file and read settings'''
|
|
53
86
|
|
|
54
87
|
self.CONFIG_KEY = "MapleLogger"
|
|
55
88
|
self.CONSOLE_LOG_LEVEL = "ConsoleLogLevel"
|
|
@@ -60,13 +93,7 @@ class Logger:
|
|
|
60
93
|
|
|
61
94
|
# Set config file path
|
|
62
95
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
self.configFile = configFile
|
|
66
|
-
|
|
67
|
-
else:
|
|
68
|
-
|
|
69
|
-
self.configFile = path.join(self.CWD, configFile)
|
|
96
|
+
self.configFile = self.__checkFilePath(configFile)
|
|
70
97
|
|
|
71
98
|
# Try to read config file
|
|
72
99
|
|
|
@@ -100,29 +127,55 @@ class Logger:
|
|
|
100
127
|
logConf[self.MAX_LOG_SIZE] = 3
|
|
101
128
|
logConf[self.WORKING_DIRECTORY] = "logs"
|
|
102
129
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
130
|
+
self.logConf = logConf
|
|
131
|
+
return logConfInstance
|
|
132
|
+
|
|
133
|
+
def __checkFilePath(self, filePath: str) -> str:
|
|
134
|
+
|
|
135
|
+
'''Check and return absolute file path'''
|
|
136
|
+
|
|
137
|
+
if path.isabs(filePath):
|
|
108
138
|
|
|
109
|
-
|
|
139
|
+
return filePath
|
|
110
140
|
|
|
111
141
|
else:
|
|
112
142
|
|
|
113
|
-
|
|
143
|
+
return path.join(os.getcwd(), filePath)
|
|
144
|
+
|
|
145
|
+
def __checkOutputDirectory(self, outputDir: str) -> None:
|
|
146
|
+
|
|
147
|
+
'''Check and set output directory'''
|
|
148
|
+
|
|
149
|
+
# Check parameter and config file
|
|
150
|
+
|
|
151
|
+
if outputDir is not None:
|
|
152
|
+
|
|
153
|
+
self.CWD = outputDir
|
|
154
|
+
|
|
155
|
+
else:
|
|
156
|
+
|
|
157
|
+
self.CWD = self.logConf.get(self.WORKING_DIRECTORY, None)
|
|
158
|
+
|
|
159
|
+
# Set absolute path
|
|
114
160
|
|
|
115
161
|
if self.CWD in {"", None}:
|
|
116
162
|
|
|
117
163
|
self.CWD = path.join(os.getcwd(), "logs")
|
|
118
|
-
logConf[self.WORKING_DIRECTORY] = self.CWD
|
|
164
|
+
self.logConf[self.WORKING_DIRECTORY] = self.CWD
|
|
119
165
|
|
|
120
166
|
elif not path.isabs(self.CWD):
|
|
121
167
|
|
|
122
168
|
self.CWD = path.join(os.getcwd(), self.CWD)
|
|
123
169
|
|
|
124
|
-
|
|
125
|
-
|
|
170
|
+
# Check if directory exists
|
|
171
|
+
|
|
172
|
+
if not path.isdir(self.CWD):
|
|
173
|
+
|
|
174
|
+
os.makedirs(self.CWD)
|
|
175
|
+
|
|
176
|
+
def __setLogFileName(self, fileMode: str) -> None:
|
|
177
|
+
|
|
178
|
+
'''Set log file name'''
|
|
126
179
|
|
|
127
180
|
if fileMode == "daily":
|
|
128
181
|
|
|
@@ -132,26 +185,15 @@ class Logger:
|
|
|
132
185
|
|
|
133
186
|
self.logfile = path.join(self.CWD, "AppLog.log")
|
|
134
187
|
|
|
135
|
-
|
|
136
|
-
############################
|
|
137
|
-
# Check log directory
|
|
138
|
-
|
|
139
|
-
if not path.isdir(path.join(self.CWD)):
|
|
140
|
-
os.makedirs(path.join(self.CWD))
|
|
141
|
-
|
|
142
|
-
#
|
|
143
|
-
############################
|
|
144
|
-
# Set function name
|
|
145
|
-
|
|
146
|
-
isGetLogger = kwargs.get("getLogger", False)
|
|
188
|
+
def __setFuncName(self, isGetLogger: bool, func: str | None = None) -> None:
|
|
147
189
|
|
|
148
190
|
if isGetLogger:
|
|
149
191
|
|
|
150
|
-
caller = inspect.
|
|
192
|
+
caller = inspect.stack()[3].frame.f_globals.get("__name__", "")
|
|
151
193
|
|
|
152
194
|
else:
|
|
153
195
|
|
|
154
|
-
caller = inspect.
|
|
196
|
+
caller = inspect.stack()[2].frame.f_globals.get("__name__", "")
|
|
155
197
|
|
|
156
198
|
if func in {None, ""}:
|
|
157
199
|
|
|
@@ -168,9 +210,7 @@ class Logger:
|
|
|
168
210
|
self.func = ""
|
|
169
211
|
self.callerName = f"{caller}."
|
|
170
212
|
|
|
171
|
-
|
|
172
|
-
############################
|
|
173
|
-
# Set max log file size
|
|
213
|
+
def __setLogFileSize(self, maxLogSize: any) -> None:
|
|
174
214
|
|
|
175
215
|
self.maxLogSize = 0
|
|
176
216
|
|
|
@@ -182,7 +222,7 @@ class Logger:
|
|
|
182
222
|
|
|
183
223
|
try:
|
|
184
224
|
|
|
185
|
-
logSize = logConf.get(self.MAX_LOG_SIZE, None)
|
|
225
|
+
logSize = self.logConf.get(self.MAX_LOG_SIZE, None)
|
|
186
226
|
|
|
187
227
|
if logSize is not None:
|
|
188
228
|
|
|
@@ -191,7 +231,7 @@ class Logger:
|
|
|
191
231
|
else:
|
|
192
232
|
|
|
193
233
|
self.maxLogSize = 3000000
|
|
194
|
-
logConf[self.MAX_LOG_SIZE] = 3
|
|
234
|
+
self.logConf[self.MAX_LOG_SIZE] = 3
|
|
195
235
|
|
|
196
236
|
except MapleLoggerException as ex:
|
|
197
237
|
|
|
@@ -203,64 +243,38 @@ class Logger:
|
|
|
203
243
|
print(f"{self.consoleColors.Red}Warning: Infinite log file size is not recommended. Using default value.{self.consoleColors.Reset}")
|
|
204
244
|
self.maxLogSize = 3000000
|
|
205
245
|
|
|
206
|
-
|
|
207
|
-
############################
|
|
208
|
-
# Set output log levels
|
|
246
|
+
def __setOutputLogLevels(self, cmdLogLevel: any, fileLogLevel: any) -> None:
|
|
209
247
|
|
|
210
|
-
self.consoleLogLevel =
|
|
211
|
-
self.fileLogLevel =
|
|
248
|
+
self.consoleLogLevel = self.__setLogLevel(self.CONSOLE_LOG_LEVEL, cmdLogLevel)
|
|
249
|
+
self.fileLogLevel = self.__setLogLevel(self.FILE_LOG_LEVEL, fileLogLevel)
|
|
212
250
|
|
|
213
|
-
|
|
251
|
+
def __setLogLevel(self, fileOrConsole, loglevel: any) -> LogLevel:
|
|
214
252
|
|
|
215
|
-
|
|
253
|
+
'''Set log level'''
|
|
216
254
|
|
|
217
|
-
|
|
255
|
+
if loglevel is not None:
|
|
218
256
|
|
|
257
|
+
tempLogLevel = loglevel
|
|
258
|
+
|
|
219
259
|
else:
|
|
220
260
|
|
|
221
|
-
|
|
261
|
+
tempLogLevel = self.logConf.get(fileOrConsole, "INFO")
|
|
222
262
|
|
|
223
|
-
if
|
|
263
|
+
if tempLogLevel is None:
|
|
224
264
|
|
|
225
|
-
|
|
226
|
-
logConf[
|
|
265
|
+
tempLogLevel = "INFO"
|
|
266
|
+
self.logConf[fileOrConsole] = tempLogLevel
|
|
227
267
|
|
|
228
268
|
try:
|
|
229
269
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
except MapleInvalidLoggerLevelException as ex:
|
|
233
|
-
|
|
234
|
-
print(f"{self.consoleColors.Red}Warning: Invalid console log level provided: [{consoleLogLevel}]. Using default value.{self.consoleColors.Reset}")
|
|
235
|
-
self.consoleLogLevel = self.LogLevel.INFO
|
|
236
|
-
|
|
237
|
-
# File log level
|
|
238
|
-
|
|
239
|
-
if fileLogLevel is not None:
|
|
240
|
-
|
|
241
|
-
self.fileLogLevel = self.isLogLevel(fileLogLevel)
|
|
242
|
-
|
|
243
|
-
else:
|
|
244
|
-
|
|
245
|
-
fileLogLevel = logConf.get(self.FILE_LOG_LEVEL, None)
|
|
246
|
-
|
|
247
|
-
if fileLogLevel is None:
|
|
248
|
-
|
|
249
|
-
fileLogLevel = "INFO"
|
|
250
|
-
logConf[self.FILE_LOG_LEVEL] = fileLogLevel
|
|
251
|
-
|
|
252
|
-
try:
|
|
253
|
-
|
|
254
|
-
self.fileLogLevel = self.toLogLevel(fileLogLevel)
|
|
270
|
+
return self.toLogLevel(tempLogLevel)
|
|
255
271
|
|
|
256
272
|
except MapleInvalidLoggerLevelException as ex:
|
|
257
273
|
|
|
258
|
-
print(f"{self.consoleColors.Red}Warning: Invalid
|
|
259
|
-
|
|
274
|
+
print(f"{self.consoleColors.Red}Warning: Invalid {fileOrConsole} provided: [{tempLogLevel}]. Using default value.{self.consoleColors.Reset}")
|
|
275
|
+
return self.LogLevel.INFO
|
|
260
276
|
|
|
261
|
-
|
|
262
|
-
############################
|
|
263
|
-
# Set file encoding
|
|
277
|
+
def __setFileEncoding(self, encoding: str) -> None:
|
|
264
278
|
|
|
265
279
|
if encoding is not None:
|
|
266
280
|
|
|
@@ -268,44 +282,42 @@ class Logger:
|
|
|
268
282
|
|
|
269
283
|
else:
|
|
270
284
|
|
|
271
|
-
fileEncoding = logConf.get(self.FILE_ENCODING, None)
|
|
285
|
+
fileEncoding = self.logConf.get(self.FILE_ENCODING, None)
|
|
272
286
|
|
|
273
287
|
if fileEncoding is None:
|
|
274
288
|
|
|
275
289
|
fileEncoding = "utf-8"
|
|
276
|
-
logConf[self.FILE_ENCODING] = fileEncoding
|
|
290
|
+
self.logConf[self.FILE_ENCODING] = fileEncoding
|
|
277
291
|
|
|
278
292
|
self.encoding = fileEncoding
|
|
279
293
|
|
|
280
|
-
|
|
294
|
+
def __saveLogSettings(self, logConfInstance: MapleJson | None) -> None:
|
|
295
|
+
|
|
296
|
+
""" Save current log settings to config file """
|
|
281
297
|
|
|
282
298
|
if logConfInstance is not None:
|
|
283
299
|
|
|
284
300
|
try:
|
|
285
301
|
|
|
286
|
-
confJson
|
|
302
|
+
confJson = logConfInstance.read()
|
|
303
|
+
|
|
304
|
+
except Exception:
|
|
305
|
+
|
|
306
|
+
confJson = {}
|
|
307
|
+
|
|
308
|
+
try:
|
|
309
|
+
|
|
310
|
+
confJson[self.CONFIG_KEY] = self.logConf
|
|
287
311
|
logConfInstance.write(confJson)
|
|
288
312
|
|
|
289
313
|
except Exception as ex:
|
|
290
314
|
|
|
291
315
|
print(f"{self.consoleColors.Red}Warning: Failed to write logger config file: {ex}{self.consoleColors.Reset}")
|
|
292
|
-
|
|
293
|
-
#
|
|
294
|
-
#####################
|
|
295
|
-
# Set log level enum
|
|
296
|
-
|
|
297
|
-
class LogLevel(IntEnum):
|
|
298
316
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
INFO = 2
|
|
302
|
-
WARN = 3
|
|
303
|
-
ERROR = 4
|
|
304
|
-
FATAL = 5
|
|
305
|
-
NONE = 6
|
|
317
|
+
# Class initialization ends here
|
|
318
|
+
#################################
|
|
306
319
|
|
|
307
|
-
|
|
308
|
-
#####################
|
|
320
|
+
#################################
|
|
309
321
|
# Getters and Setters
|
|
310
322
|
|
|
311
323
|
def getLogFile(self) -> str:
|
|
@@ -454,8 +466,12 @@ class Logger:
|
|
|
454
466
|
|
|
455
467
|
def isLogLevel(self, lLStr: str) -> LogLevel:
|
|
456
468
|
|
|
469
|
+
'''Check if string is a valid log level'''
|
|
470
|
+
|
|
471
|
+
logLevelStr = lLStr.upper()
|
|
472
|
+
|
|
457
473
|
for lLevel in self.LogLevel:
|
|
458
|
-
if
|
|
474
|
+
if logLevelStr == lLevel.name:
|
|
459
475
|
return lLevel
|
|
460
476
|
|
|
461
477
|
return -1
|
|
@@ -470,6 +486,12 @@ class Logger:
|
|
|
470
486
|
Output log to log file and console.
|
|
471
487
|
"""
|
|
472
488
|
|
|
489
|
+
# Precheck log level
|
|
490
|
+
|
|
491
|
+
if loglevel < self.consoleLogLevel and loglevel < self.fileLogLevel:
|
|
492
|
+
|
|
493
|
+
return
|
|
494
|
+
|
|
473
495
|
# Console colors
|
|
474
496
|
|
|
475
497
|
Black = self.consoleColors.Black
|
|
@@ -532,8 +554,20 @@ class Logger:
|
|
|
532
554
|
print(f"[{col}{loglevel.name:5}{Reset}]{Green}{self.func}{Reset} {bBlack}{callerFunc}({callerLine}){Reset} {message}")
|
|
533
555
|
|
|
534
556
|
if loglevel >= self.fileLogLevel:
|
|
535
|
-
|
|
536
|
-
|
|
557
|
+
|
|
558
|
+
for i in range(3):
|
|
559
|
+
|
|
560
|
+
try:
|
|
561
|
+
|
|
562
|
+
with open(self.logfile, "a", encoding=self.encoding) as f:
|
|
563
|
+
print(f"({self.pid}) {f"{datetime.now():%F %X.%f}"[:-3]} [{loglevel.name:5}]{self.func} {self.callerName}{callerFunc}({callerLine}) {message}", file=f)
|
|
564
|
+
|
|
565
|
+
break
|
|
566
|
+
|
|
567
|
+
except IOError:
|
|
568
|
+
|
|
569
|
+
if i == 2:
|
|
570
|
+
raise
|
|
537
571
|
|
|
538
572
|
except Exception as ex:
|
|
539
573
|
|
|
@@ -676,7 +710,7 @@ class Logger:
|
|
|
676
710
|
################################
|
|
677
711
|
# Save log settings
|
|
678
712
|
|
|
679
|
-
def saveLogSettings(self, configFile: str =
|
|
713
|
+
def saveLogSettings(self, configFile: str = None) -> None:
|
|
680
714
|
|
|
681
715
|
"""Save current log settings to config file"""
|
|
682
716
|
|
|
@@ -684,13 +718,11 @@ class Logger:
|
|
|
684
718
|
|
|
685
719
|
# Set config file path
|
|
686
720
|
|
|
687
|
-
if
|
|
721
|
+
if configFile is None:
|
|
688
722
|
|
|
689
|
-
|
|
723
|
+
configFile = self.configFile
|
|
690
724
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
configFilePath = path.join(os.getcwd(), configFile)
|
|
725
|
+
configFilePath = self.__checkFilePath(configFile)
|
|
694
726
|
|
|
695
727
|
# Try to read config file
|
|
696
728
|
|
|
@@ -748,6 +780,25 @@ def getLogger(name: str = "", **kwargs) -> Logger:
|
|
|
748
780
|
if name not in _loggers:
|
|
749
781
|
kwargs["getLogger"] = True
|
|
750
782
|
_loggers[name] = Logger(func=name, **kwargs)
|
|
783
|
+
|
|
784
|
+
return _loggers[name]
|
|
785
|
+
|
|
786
|
+
def getDailyLogger(name: str = "", **kwargs) -> Logger:
|
|
787
|
+
"""
|
|
788
|
+
Get or create a daily Logger instance.
|
|
789
|
+
|
|
790
|
+
Args:
|
|
791
|
+
name: Logger name (usually __name__ of the calling module)
|
|
792
|
+
**kwargs: Arguments to pass to Logger constructor if creating new instance
|
|
793
|
+
|
|
794
|
+
Returns:
|
|
795
|
+
Logger instance
|
|
796
|
+
"""
|
|
797
|
+
|
|
798
|
+
if name not in _loggers:
|
|
799
|
+
kwargs["getLogger"] = True
|
|
800
|
+
_loggers[name] = Logger(func=name, fileMode="daily", **kwargs)
|
|
801
|
+
|
|
751
802
|
return _loggers[name]
|
|
752
803
|
|
|
753
804
|
""" * * * * * * * * * * * * * """
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: MapleX
|
|
3
|
-
Version: 3.0.0.
|
|
3
|
+
Version: 3.0.0.dev4
|
|
4
4
|
Summary: A Python library for simple logging, json file operations, Maple file format operations, and console color utilities.
|
|
5
5
|
Author: RyujiHazama
|
|
6
6
|
Project-URL: PyPI, https://pypi.org/project/MapleX/
|
|
@@ -22,6 +22,11 @@ Dynamic: license-file
|
|
|
22
22
|
|
|
23
23
|
# MapleX
|
|
24
24
|
|
|
25
|
+

|
|
26
|
+

|
|
27
|
+

|
|
28
|
+

|
|
29
|
+
|
|
25
30
|
MapleX is a Python library for simple logging, json file operations, Maple file format operations, and console color utilities.
|
|
26
31
|
|
|
27
32
|
***You can install the package from pip with the following command.***
|
|
@@ -59,7 +64,7 @@ logger = maplex.getLogger("FunctionName")
|
|
|
59
64
|
logger.info("Hello there!")
|
|
60
65
|
```
|
|
61
66
|
|
|
62
|
-
This outputs to console:
|
|
67
|
+
This outputs to the console:
|
|
63
68
|
|
|
64
69
|
```console
|
|
65
70
|
[INFO ][FunctionName] <module>(4) Hello there!
|
|
@@ -77,9 +82,9 @@ Also outputs to the log file:
|
|
|
77
82
|
|
|
78
83
|
## MapleJson
|
|
79
84
|
|
|
80
|
-
MapleJson class is a library class for
|
|
85
|
+
MapleJson class is a library class for converting data between `dict` data and JSON-formatted file data.
|
|
81
86
|
|
|
82
|
-
You can read, write and also encrypt a JSON file as a `dict` data.
|
|
87
|
+
You can read, write, and also encrypt a JSON file as a `dict` data.
|
|
83
88
|
|
|
84
89
|
[More details](https://github.com/Ryuji-Hazama/MapleTree/blob/main/readmes/README_Json.md)
|
|
85
90
|
|
|
@@ -152,20 +157,20 @@ All datas after "\nEOF\n" will be ignored
|
|
|
152
157
|
|
|
153
158
|
## MapleTree Class
|
|
154
159
|
|
|
155
|
-
MapleTree class is a Python library for
|
|
160
|
+
MapleTree class is a Python library for reading, editing, and writeing the Maple formatted file from the Python code.
|
|
156
161
|
You can also automatically encrypt the file data using the library functions.
|
|
157
162
|
|
|
158
163
|
[More details](https://github.com/Ryuji-Hazama/MapleTree/blob/main/readmes/README_MapleTree.md#mapletree-class)
|
|
159
164
|
|
|
160
165
|
## Exceptions
|
|
161
166
|
|
|
162
|
-
Excption classes are the specialized classes for MapleX to make your
|
|
167
|
+
Excption classes are the specialized classes for MapleX to make your debugging easier.
|
|
163
168
|
|
|
164
169
|
[More details](https://github.com/Ryuji-Hazama/MapleTree/blob/main/readmes/README_Exceptions.md#exceptions)
|
|
165
170
|
|
|
166
171
|
## Console Colors
|
|
167
172
|
|
|
168
|
-
ConsoleColors class is a class library for color-
|
|
173
|
+
ConsoleColors class is a class library for color-highlighting the standard output.
|
|
169
174
|
|
|
170
175
|
[More details](https://github.com/Ryuji-Hazama/MapleTree/blob/main/readmes/README_ConsoleColors.md)
|
|
171
176
|
|
|
@@ -174,9 +179,12 @@ All datas after "\nEOF\n" will be ignored
|
|
|
174
179
|
### From PyPI
|
|
175
180
|
|
|
176
181
|
```bash
|
|
177
|
-
[python[3] -m] pip install MapleX [--break-system-packages]
|
|
182
|
+
[python[3] -m] pip install MapleX [--upgrade] [--break-system-packages]
|
|
178
183
|
```
|
|
179
184
|
|
|
185
|
+
- `--upgrade` option for upgrade from older version.
|
|
186
|
+
- `--break-system-package` option for Python on Linux OS outside the `venv`. ***This might brak the system Python package dependencies.***
|
|
187
|
+
|
|
180
188
|
### Manual Installation
|
|
181
189
|
|
|
182
190
|
1. Download `./dist/maplex-<version>-py3-none-any.whl`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
maplex/__init__.py,sha256=GTwzV48uJ_Ol4GOANK481QYYuNI7HdkRuWHD3BLcbIg,1433
|
|
2
|
+
maplex/json.py,sha256=JOJDri9_5cMUoRQBEwFak9VmgIGkZ5D-cLpON7wPK58,4287
|
|
3
|
+
maplex/mapleColors.py,sha256=8xhI3yMce9LC0ym1CcrXttchJiTSsmKdt6XWK2zKVoA,1077
|
|
4
|
+
maplex/mapleExceptions.py,sha256=_45JSNVJE5VHJrJeu2mJzRvSYnPzMh3olSLUF75oxF0,4679
|
|
5
|
+
maplex/mapleLogger.py,sha256=a7vUHa5tftXiF_xlIE6AhMCgyCIDJDQJgj-9I8oKvqg,20999
|
|
6
|
+
maplex/mapleTreeEditor.py,sha256=5596bARJWHXyGUeXWRYx9lKSfaZdBmGQLvkF_OiKzZ0,29249
|
|
7
|
+
maplex/utils.py,sha256=TcUdfn9uhk9zwMTxtWgsZ1ZKdc2_i0ysgrksMbzvX1I,603
|
|
8
|
+
maplex-3.0.0.dev4.dist-info/licenses/LICENSE,sha256=M7R85ReZ2srvowIPO_c9sHI3DV7QmxnLH93esXVhwGI,1068
|
|
9
|
+
maplex-3.0.0.dev4.dist-info/METADATA,sha256=coYAsqgCWpFhJZXPYkcWSSD27EXrrHa39o4Jjz9e57o,6534
|
|
10
|
+
maplex-3.0.0.dev4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
11
|
+
maplex-3.0.0.dev4.dist-info/top_level.txt,sha256=ME8uFV82K0y0KYJrHVTMgc0hEBV67iXXUKsvom7BO5g,7
|
|
12
|
+
maplex-3.0.0.dev4.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
maplex/__init__.py,sha256=3n0cGNfxTHHe8uA1G06huai9s9yK6xUhJPS0Iq7MIDQ,1400
|
|
2
|
-
maplex/mapleColors.py,sha256=8xhI3yMce9LC0ym1CcrXttchJiTSsmKdt6XWK2zKVoA,1077
|
|
3
|
-
maplex/mapleExceptions.py,sha256=_45JSNVJE5VHJrJeu2mJzRvSYnPzMh3olSLUF75oxF0,4679
|
|
4
|
-
maplex/mapleJson.py,sha256=bNhR-geW2yjYmnyfhcp3sesyO1sxoQH98nAcvzU_PFk,3855
|
|
5
|
-
maplex/mapleLogger.py,sha256=FBccdbISXjo7dxvOB-Rkt_Dsh_06beJzE3CGiGjqKUA,19335
|
|
6
|
-
maplex/mapleTreeEditor.py,sha256=5596bARJWHXyGUeXWRYx9lKSfaZdBmGQLvkF_OiKzZ0,29249
|
|
7
|
-
maplex/utils.py,sha256=TcUdfn9uhk9zwMTxtWgsZ1ZKdc2_i0ysgrksMbzvX1I,603
|
|
8
|
-
maplex-3.0.0.dev2.dist-info/licenses/LICENSE,sha256=M7R85ReZ2srvowIPO_c9sHI3DV7QmxnLH93esXVhwGI,1068
|
|
9
|
-
maplex-3.0.0.dev2.dist-info/METADATA,sha256=NXqwtzv7FXGAHm2hnYeeqdxaj0E9zhKiMiV6DTFwVFQ,6027
|
|
10
|
-
maplex-3.0.0.dev2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
11
|
-
maplex-3.0.0.dev2.dist-info/top_level.txt,sha256=ME8uFV82K0y0KYJrHVTMgc0hEBV67iXXUKsvom7BO5g,7
|
|
12
|
-
maplex-3.0.0.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|