MapleX 3.1.2__py3-none-any.whl → 3.2.0.dev2__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 +1 -1
- maplex/library/logger/__init__.py +2 -1
- maplex/library/logger/config.py +105 -18
- maplex/library/logger/consts/__init__.py +43 -0
- maplex/library/logger/consts/config_keys.py +20 -0
- maplex/library/logger/consts/defaults.py +6 -0
- maplex/library/logger/consts/dict_keys.py +11 -0
- maplex/library/logger/formatter.py +9 -6
- maplex/mapleLogger.py +23 -11
- {maplex-3.1.2.dist-info → maplex-3.2.0.dev2.dist-info}/METADATA +3 -3
- maplex-3.2.0.dev2.dist-info/RECORD +22 -0
- maplex/library/logger/consts.py +0 -28
- maplex-3.1.2.dist-info/RECORD +0 -19
- {maplex-3.1.2.dist-info → maplex-3.2.0.dev2.dist-info}/WHEEL +0 -0
- {maplex-3.1.2.dist-info → maplex-3.2.0.dev2.dist-info}/licenses/LICENSE +0 -0
- {maplex-3.1.2.dist-info → maplex-3.2.0.dev2.dist-info}/top_level.txt +0 -0
maplex/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Split mapleLogger.py into multiple files for better organization and maintainability.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from .config import LoggerConfig
|
|
5
|
+
from .config import LoggerConfig, TimeStamp
|
|
6
6
|
from .file_handler import FileHandler
|
|
7
7
|
from .formatter import Formatter
|
|
8
8
|
from .log_levels import LogLevel
|
|
@@ -14,6 +14,7 @@ __all__ = [
|
|
|
14
14
|
"LoggerConfig",
|
|
15
15
|
"LogLevel",
|
|
16
16
|
"getConsoleColors",
|
|
17
|
+
"TimeStamp",
|
|
17
18
|
"toLogLevel",
|
|
18
19
|
"toLogSize",
|
|
19
20
|
"isLogLevel"
|
maplex/library/logger/config.py
CHANGED
|
@@ -21,6 +21,17 @@ from .utilities import *
|
|
|
21
21
|
from library.logger.log_levels import LogLevel
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
class TimeStamp(BaseModel):
|
|
25
|
+
|
|
26
|
+
timestampFormat: str | None = None
|
|
27
|
+
digits: int | None = None
|
|
28
|
+
|
|
29
|
+
class Formats(BaseModel):
|
|
30
|
+
|
|
31
|
+
consoleFormat: str | None = None
|
|
32
|
+
fileFormat: str | None = None
|
|
33
|
+
timestamp: TimeStamp | None = None
|
|
34
|
+
|
|
24
35
|
class LoggerConfig(BaseModel):
|
|
25
36
|
|
|
26
37
|
func: str | None = None
|
|
@@ -32,12 +43,10 @@ class LoggerConfig(BaseModel):
|
|
|
32
43
|
fileMode: Literal["append", "overwrite", "daily"] | None = None
|
|
33
44
|
configFile: str = "config.json"
|
|
34
45
|
encoding: str | None = None
|
|
35
|
-
timestampFormat: str | None = None
|
|
36
46
|
getLogger: bool | None = None
|
|
37
47
|
consoleAlignWidth: int | None = None
|
|
38
48
|
fileAlignWidth: int | None = None
|
|
39
|
-
|
|
40
|
-
fileFormat: str = FILE_FORMAT
|
|
49
|
+
formats: Formats | None = None
|
|
41
50
|
|
|
42
51
|
logConfInstance: None = None
|
|
43
52
|
logConf: dict[str, object] | None = None
|
|
@@ -51,9 +60,7 @@ class LoggerConfig(BaseModel):
|
|
|
51
60
|
try:
|
|
52
61
|
|
|
53
62
|
super().__init__(**config)
|
|
54
|
-
|
|
55
63
|
self.consoleColors = getConsoleColors()
|
|
56
|
-
|
|
57
64
|
self.logConfInstance = self.checkConfigFile(config.get(CONFIG_FILE, self.configFile))
|
|
58
65
|
self.checkOutputDirectory(config.get(WORKING_DIRECTORY, None))
|
|
59
66
|
self.setLogFileName(config.get(FILE_MODE, "append"))
|
|
@@ -62,11 +69,13 @@ class LoggerConfig(BaseModel):
|
|
|
62
69
|
self.setLogFileSize(config.get(MAX_LOG_SIZE, None))
|
|
63
70
|
self.setOutputLogLevels(config.get(CONSOLE_LOG_LEVEL, None), config.get(FILE_LOG_LEVEL, None))
|
|
64
71
|
self.setFileEncoding(config.get(FILE_ENCODING, None))
|
|
65
|
-
self.setTimestampFormat(config.get(
|
|
72
|
+
self.setTimestampFormat(config.get(PARAM_TIMESTAMP, None))
|
|
73
|
+
self.setOutputFormat(config.get(CONSOLE_LOG_FORMAT, None), config.get(FILE_LOG_FORMAT, None))
|
|
66
74
|
self.saveLogSettings(self.logConfInstance)
|
|
67
75
|
|
|
68
76
|
except Exception as ex:
|
|
69
77
|
|
|
78
|
+
print(ex)
|
|
70
79
|
print(f"{self.consoleColors.Red}Error: Failed to initialize logger config: {ex}{self.consoleColors.Reset}")
|
|
71
80
|
raise ex
|
|
72
81
|
|
|
@@ -245,10 +254,26 @@ class LoggerConfig(BaseModel):
|
|
|
245
254
|
print(f"{self.consoleColors.Red}Warning: Infinite log file size is not recommended. Using default value.{self.consoleColors.Reset}")
|
|
246
255
|
self.maxLogSize = 3000000
|
|
247
256
|
|
|
257
|
+
def getLogLevel(self) -> None:
|
|
258
|
+
|
|
259
|
+
'''
|
|
260
|
+
Get LogLevel configuration from config file.
|
|
261
|
+
Set namespace specific LogLevel if available, otherwise set default LogLevel.
|
|
262
|
+
'''
|
|
263
|
+
|
|
264
|
+
namespaceSettings = self.logConf.get(NAME_SPACES, [])
|
|
265
|
+
thisNamespaceSettings = next((ns for ns in namespaceSettings if ns.get(NAME_SPACE) == self.callerName), None)
|
|
266
|
+
|
|
267
|
+
if thisNamespaceSettings is not None:
|
|
268
|
+
|
|
269
|
+
self.consoleLogLevel = thisNamespaceSettings.get(CONSOLE_LOG_LEVEL, None)
|
|
270
|
+
self.fileLogLevel = thisNamespaceSettings.get(FILE_LOG_LEVEL, None)
|
|
271
|
+
|
|
248
272
|
def setOutputLogLevels(self, cmdLogLevel: object, fileLogLevel: object) -> None:
|
|
249
273
|
|
|
250
|
-
self.
|
|
251
|
-
self.
|
|
274
|
+
self.getLogLevel()
|
|
275
|
+
self.consoleLogLevel = self.__setLogLevel(CONSOLE_LOG_LEVEL, cmdLogLevel if self.consoleLogLevel is None else self.consoleLogLevel)
|
|
276
|
+
self.fileLogLevel = self.__setLogLevel(FILE_LOG_LEVEL, fileLogLevel if self.fileLogLevel is None else self.fileLogLevel)
|
|
252
277
|
|
|
253
278
|
def __setLogLevel(self, fileOrConsole, loglevel: object) -> LogLevel:
|
|
254
279
|
|
|
@@ -260,7 +285,7 @@ class LoggerConfig(BaseModel):
|
|
|
260
285
|
|
|
261
286
|
else:
|
|
262
287
|
|
|
263
|
-
tempLogLevel = self.logConf.get(fileOrConsole,
|
|
288
|
+
tempLogLevel = self.logConf.get(fileOrConsole, None)
|
|
264
289
|
|
|
265
290
|
if tempLogLevel is None:
|
|
266
291
|
|
|
@@ -293,24 +318,86 @@ class LoggerConfig(BaseModel):
|
|
|
293
318
|
|
|
294
319
|
self.encoding = fileEncoding
|
|
295
320
|
|
|
296
|
-
def setTimestampFormat(self, timestampFormat:
|
|
321
|
+
def setTimestampFormat(self, timestampFormat: dict) -> None:
|
|
297
322
|
|
|
298
323
|
"""Set timestamp format for logs. Default is "%F %X.%f" (e.g. 2024-06-01 12:34:56.789). You can set this in config file with key "TimestampFormat"."""
|
|
299
324
|
|
|
325
|
+
if self.formats is None:
|
|
326
|
+
|
|
327
|
+
self.formats = Formats()
|
|
328
|
+
|
|
329
|
+
if self.formats.timestamp is None:
|
|
330
|
+
|
|
331
|
+
self.formats.timestamp = TimeStamp()
|
|
332
|
+
|
|
300
333
|
if timestampFormat is not None:
|
|
301
334
|
|
|
302
|
-
self.timestampFormat = timestampFormat
|
|
335
|
+
self.formats.timestamp.timestampFormat = timestampFormat.get(FORMAT, None)
|
|
336
|
+
self.formats.timestamp.digits = timestampFormat.get(DIGITS, 3)
|
|
303
337
|
|
|
304
338
|
else:
|
|
305
339
|
|
|
306
|
-
|
|
340
|
+
timestampSettings = self.logConf.get(FORMATS, {}).get(TIMESTAMP, {})
|
|
341
|
+
configTimestampFormat = timestampSettings.get(FORMAT, None)
|
|
342
|
+
configTimestampDigits = timestampSettings.get(DIGITS, None)
|
|
307
343
|
|
|
308
344
|
if configTimestampFormat is None:
|
|
309
345
|
|
|
310
|
-
configTimestampFormat =
|
|
311
|
-
|
|
346
|
+
configTimestampFormat = TIMESTAMP_FORMAT
|
|
347
|
+
timestampSettings[FORMAT] = configTimestampFormat
|
|
348
|
+
self.logConf.setdefault(FORMATS, {})[TIMESTAMP] = timestampSettings
|
|
349
|
+
|
|
350
|
+
if configTimestampDigits is None:
|
|
351
|
+
|
|
352
|
+
configTimestampDigits = MILLISECOND_DIGITS
|
|
353
|
+
timestampSettings[DIGITS] = configTimestampDigits
|
|
354
|
+
self.logConf.setdefault(FORMATS, {})[TIMESTAMP] = timestampSettings
|
|
355
|
+
|
|
356
|
+
if "TimestampFormat" in self.logConf:
|
|
357
|
+
|
|
358
|
+
# Show warning if old config key is used
|
|
359
|
+
print(f"{self.consoleColors.Yellow}Warning: 'TimestampFormat' key in config file is deprecated. Please use 'Formats.Timestamp' instead.{self.consoleColors.Reset}\nMore details: https://github.com/Ryuji-Hazama/MapleTree/blob/main/readmes/README_Logger.md#settings")
|
|
360
|
+
|
|
361
|
+
self.formats.timestamp.timestampFormat = configTimestampFormat
|
|
362
|
+
self.formats.timestamp.digits = configTimestampDigits
|
|
363
|
+
|
|
364
|
+
def setOutputFormat(self, consoleFormat: str, fileFormat: str) -> None:
|
|
365
|
+
|
|
366
|
+
"""Set output format for console and file logs. Default is "[{level}]{func} {callerFunc}{callerLine}" for console and "({pid}) {timestamp} [{level}]{func} {callerName}{callerFunc}({callerLine})" for file. You can set this in config file with keys "ConsoleLogFormat" and "FileLogFormat"."""
|
|
367
|
+
|
|
368
|
+
if self.formats is None:
|
|
369
|
+
|
|
370
|
+
self.formats = Formats()
|
|
371
|
+
|
|
372
|
+
if consoleFormat is not None:
|
|
373
|
+
|
|
374
|
+
self.formats.consoleFormat = consoleFormat
|
|
375
|
+
|
|
376
|
+
else:
|
|
377
|
+
|
|
378
|
+
self.formats.consoleFormat = self.logConf.get(CONSOLE_LOG_FORMAT, None)
|
|
379
|
+
|
|
380
|
+
if self.formats.consoleFormat is None:
|
|
381
|
+
|
|
382
|
+
self.formats.consoleFormat = CONSOLE_FORMAT
|
|
383
|
+
formatConf = self.logConf.get(FORMATS, {})
|
|
384
|
+
formatConf[CONSOLE_LOG_FORMAT] = CONSOLE_FORMAT
|
|
385
|
+
self.logConf[FORMATS] = formatConf
|
|
386
|
+
|
|
387
|
+
if fileFormat is not None:
|
|
388
|
+
|
|
389
|
+
self.formats.fileFormat = fileFormat
|
|
390
|
+
|
|
391
|
+
else:
|
|
392
|
+
|
|
393
|
+
self.formats.fileFormat = self.logConf.get(FILE_LOG_FORMAT, None)
|
|
394
|
+
|
|
395
|
+
if self.formats.fileFormat is None:
|
|
312
396
|
|
|
313
|
-
|
|
397
|
+
self.formats.fileFormat = FILE_FORMAT
|
|
398
|
+
formatConf = self.logConf.get(FORMATS, {})
|
|
399
|
+
formatConf[FILE_LOG_FORMAT] = FILE_FORMAT
|
|
400
|
+
self.logConf[FORMATS] = formatConf
|
|
314
401
|
|
|
315
402
|
def saveLogSettings(self, logConfInstance: MapleJson | None) -> None:
|
|
316
403
|
|
|
@@ -348,12 +435,12 @@ class LoggerConfig(BaseModel):
|
|
|
348
435
|
MAX_LOG_SIZE: self.maxLogSize,
|
|
349
436
|
FILE_MODE: "daily" if self.logfile and "log_" in self.logfile else "append",
|
|
350
437
|
FILE_ENCODING: self.encoding,
|
|
351
|
-
|
|
438
|
+
TIMESTAMP: self.formats.timestamp if self.formats.timestamp else None,
|
|
352
439
|
GET_LOGGER: bool(self.func),
|
|
353
440
|
CONSOLE_ALIGN_WIDTH: self.consoleAlignWidth,
|
|
354
441
|
FILE_ALIGN_WIDTH: self.fileAlignWidth,
|
|
355
|
-
|
|
356
|
-
|
|
442
|
+
PARAM_CONSOLE_FORMAT: self.formats.consoleFormat,
|
|
443
|
+
PARAM_FILE_FORMAT: self.formats.fileFormat,
|
|
357
444
|
PROCESS_ID: self.pid
|
|
358
445
|
}
|
|
359
446
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from .config_keys import *
|
|
2
|
+
from .defaults import *
|
|
3
|
+
from .dict_keys import *
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"CONFIG_KEY",
|
|
7
|
+
"CONSOLE",
|
|
8
|
+
"FILE",
|
|
9
|
+
"CONSOLE_LOG_LEVEL",
|
|
10
|
+
"FILE_LOG_LEVEL",
|
|
11
|
+
"MAX_LOG_SIZE",
|
|
12
|
+
"FILE_MODE",
|
|
13
|
+
"WORKING_DIRECTORY",
|
|
14
|
+
"FILE_ENCODING",
|
|
15
|
+
"FORMATS",
|
|
16
|
+
"TIMESTAMP",
|
|
17
|
+
"FORMAT",
|
|
18
|
+
"DIGITS",
|
|
19
|
+
"ALIGN_WIDTH",
|
|
20
|
+
"CONSOLE_LOG_FORMAT",
|
|
21
|
+
"FILE_LOG_FORMAT",
|
|
22
|
+
"NAME_SPACES",
|
|
23
|
+
"NAME_SPACE",
|
|
24
|
+
# Dictionary keys for internal use
|
|
25
|
+
"GET_LOGGER",
|
|
26
|
+
"FUNC",
|
|
27
|
+
"CONFIG_FILE",
|
|
28
|
+
"CONSOLE_ALIGN_WIDTH",
|
|
29
|
+
"FILE_ALIGN_WIDTH",
|
|
30
|
+
"CALLER_NAME",
|
|
31
|
+
"PROCESS_ID",
|
|
32
|
+
"PARAM_TIMESTAMP",
|
|
33
|
+
"PARAM_FORMATS",
|
|
34
|
+
"PARAM_CONSOLE_FORMAT",
|
|
35
|
+
"PARAM_FILE_FORMAT",
|
|
36
|
+
# Default values
|
|
37
|
+
"FILE_FORMAT",
|
|
38
|
+
"CONSOLE_FORMAT",
|
|
39
|
+
"TIMESTAMP_FORMAT",
|
|
40
|
+
"MILLISECOND_DIGITS",
|
|
41
|
+
"FILE_MODE_OVERWRITE",
|
|
42
|
+
"FILE_MODE_DAILY",
|
|
43
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CONFIG_KEY = "MapleLogger"
|
|
2
|
+
CONSOLE = "Console"
|
|
3
|
+
FILE = "File"
|
|
4
|
+
CONSOLE_LOG_LEVEL = "ConsoleLogLevel"
|
|
5
|
+
FILE_LOG_LEVEL = "FileLogLevel"
|
|
6
|
+
MAX_LOG_SIZE = "MaxLogSize"
|
|
7
|
+
FILE_MODE = "FileMode"
|
|
8
|
+
WORKING_DIRECTORY = "WorkingDirectory"
|
|
9
|
+
FILE_ENCODING = "FileEncoding"
|
|
10
|
+
|
|
11
|
+
FORMATS = "Formats"
|
|
12
|
+
CONSOLE_LOG_FORMAT = "ConsoleLogFormat"
|
|
13
|
+
FILE_LOG_FORMAT = "FileLogFormat"
|
|
14
|
+
TIMESTAMP = "Timestamp"
|
|
15
|
+
FORMAT = "Format"
|
|
16
|
+
DIGITS = "Digits"
|
|
17
|
+
|
|
18
|
+
ALIGN_WIDTH = "AlignWidth"
|
|
19
|
+
NAME_SPACES = "NameSpaces"
|
|
20
|
+
NAME_SPACE = "NameSpace"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
FILE_FORMAT = '({pid}) {timestamp} [{level}]{func} {callerName}{callerFunc}({callerLine})'
|
|
2
|
+
CONSOLE_FORMAT = '[{level}]{func} {callerFunc}{callerLine}'
|
|
3
|
+
TIMESTAMP_FORMAT = "%F %X.%f"
|
|
4
|
+
MILLISECOND_DIGITS = None
|
|
5
|
+
FILE_MODE_OVERWRITE = 'overwrite'
|
|
6
|
+
FILE_MODE_DAILY = 'daily'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
CONFIG_FILE = "configFile"
|
|
2
|
+
FUNC = "func"
|
|
3
|
+
GET_LOGGER = "getLogger"
|
|
4
|
+
CONSOLE_ALIGN_WIDTH = "consoleAlignWidth"
|
|
5
|
+
FILE_ALIGN_WIDTH = "fileAlignWidth"
|
|
6
|
+
CALLER_NAME = "CallerName"
|
|
7
|
+
PROCESS_ID = "pid"
|
|
8
|
+
PARAM_TIMESTAMP = "timestamp"
|
|
9
|
+
PARAM_FORMATS = "formats"
|
|
10
|
+
PARAM_CONSOLE_FORMAT = "consoleFormat"
|
|
11
|
+
PARAM_FILE_FORMAT = "fileFormat"
|
|
@@ -7,6 +7,7 @@ from datetime import datetime
|
|
|
7
7
|
import inspect
|
|
8
8
|
import os
|
|
9
9
|
|
|
10
|
+
from .config import TimeStamp
|
|
10
11
|
from .consts import *
|
|
11
12
|
from .log_levels import *
|
|
12
13
|
from .utilities import *
|
|
@@ -29,8 +30,10 @@ class Formatter:
|
|
|
29
30
|
self.consoleColors = getConsoleColors()
|
|
30
31
|
self.logLevel = LogLevel
|
|
31
32
|
self.config = config
|
|
32
|
-
self.consoleFormat = config.get(
|
|
33
|
-
self.fileFormat = config.get(
|
|
33
|
+
self.consoleFormat = config.get(PARAM_CONSOLE_FORMAT, CONSOLE_FORMAT)
|
|
34
|
+
self.fileFormat = config.get(PARAM_FILE_FORMAT, FILE_FORMAT)
|
|
35
|
+
self.timestampFormat = self.config.get(TIMESTAMP, TimeStamp()).timestampFormat or TIMESTAMP_FORMAT
|
|
36
|
+
self.timestampDigits = config.get(TIMESTAMP, TimeStamp()).digits or MILLISECOND_DIGITS
|
|
34
37
|
self.pid = os.getpid()
|
|
35
38
|
self.COLOR_CODE_LENGTH = 5
|
|
36
39
|
self.COLOR_CODE_RESET_LENGTH = 4
|
|
@@ -69,7 +72,7 @@ class Formatter:
|
|
|
69
72
|
|
|
70
73
|
return colorCodeLength
|
|
71
74
|
|
|
72
|
-
def __getCurrentTimestamp(self
|
|
75
|
+
def __getCurrentTimestamp(self) -> str:
|
|
73
76
|
|
|
74
77
|
"""
|
|
75
78
|
Get the current timestamp formatted according to the specified format string.
|
|
@@ -78,7 +81,7 @@ class Formatter:
|
|
|
78
81
|
:return: The current timestamp as a formatted string.
|
|
79
82
|
"""
|
|
80
83
|
|
|
81
|
-
return datetime.now().strftime(timestampFormat)
|
|
84
|
+
return datetime.now().strftime(self.timestampFormat)[:self.timestampDigits]
|
|
82
85
|
|
|
83
86
|
def __getLogLevelColor(self, logLevel: LogLevel) -> str:
|
|
84
87
|
|
|
@@ -142,7 +145,7 @@ class Formatter:
|
|
|
142
145
|
|
|
143
146
|
if '{timestamp}' in consoleFormat:
|
|
144
147
|
|
|
145
|
-
timestamp = self.__getCurrentTimestamp(
|
|
148
|
+
timestamp = self.__getCurrentTimestamp()
|
|
146
149
|
consoleFormat = consoleFormat.replace('{timestamp}', timestamp)
|
|
147
150
|
|
|
148
151
|
if '{level}' in consoleFormat:
|
|
@@ -193,7 +196,7 @@ class Formatter:
|
|
|
193
196
|
|
|
194
197
|
if '{timestamp}' in fileFormat:
|
|
195
198
|
|
|
196
|
-
timestamp = self.__getCurrentTimestamp(
|
|
199
|
+
timestamp = self.__getCurrentTimestamp()
|
|
197
200
|
fileFormat = fileFormat.replace('{timestamp}', timestamp)
|
|
198
201
|
|
|
199
202
|
if '{level}' in fileFormat:
|
maplex/mapleLogger.py
CHANGED
|
@@ -28,7 +28,7 @@ class Logger:
|
|
|
28
28
|
fileMode: Literal["append", "overwrite", "daily"] | None = None,
|
|
29
29
|
configFile: str = "config.json",
|
|
30
30
|
encoding: str | None = None,
|
|
31
|
-
|
|
31
|
+
timestamp: TimeStamp | None = None,
|
|
32
32
|
**kwargs
|
|
33
33
|
) -> None:
|
|
34
34
|
|
|
@@ -48,7 +48,7 @@ class Logger:
|
|
|
48
48
|
"fileMode": fileMode,
|
|
49
49
|
"configFile": configFile,
|
|
50
50
|
"encoding": encoding,
|
|
51
|
-
"
|
|
51
|
+
"timestamp": timestamp,
|
|
52
52
|
"getLogger": kwargs.get("getLogger", False),
|
|
53
53
|
"consoleAlignWidth": kwargs.get("consoleAlignWidth", 16),
|
|
54
54
|
"fileAlignWidth": kwargs.get("fileAlignWidth", 4)
|
|
@@ -235,21 +235,33 @@ class Logger:
|
|
|
235
235
|
################################
|
|
236
236
|
# Error
|
|
237
237
|
|
|
238
|
-
def error(self, object: any):
|
|
238
|
+
def error(self, object: any, exception: Exception | None = None):
|
|
239
239
|
|
|
240
240
|
'''Error log'''
|
|
241
241
|
|
|
242
|
-
|
|
242
|
+
if exception is None:
|
|
243
|
+
|
|
244
|
+
self.logWriter(self.LogLevel.ERROR, object, callerDepth=self.DEFAULT_CALLER_DEPTH)
|
|
245
|
+
|
|
246
|
+
else:
|
|
247
|
+
|
|
248
|
+
self.ShowError(exception, message=f"{object}", fatal=False, additionalCallerDepth=1)
|
|
243
249
|
|
|
244
250
|
#
|
|
245
251
|
################################
|
|
246
252
|
# Fatal
|
|
247
253
|
|
|
248
|
-
def fatal(self, object: any):
|
|
254
|
+
def fatal(self, object: any, exception: Exception | None = None):
|
|
249
255
|
|
|
250
256
|
'''Fatal log'''
|
|
251
257
|
|
|
252
|
-
|
|
258
|
+
if exception is None:
|
|
259
|
+
|
|
260
|
+
self.logWriter(self.LogLevel.FATAL, object, callerDepth=self.DEFAULT_CALLER_DEPTH)
|
|
261
|
+
|
|
262
|
+
else:
|
|
263
|
+
|
|
264
|
+
self.ShowError(exception, message=f"{object}", fatal=True, additionalCallerDepth=1)
|
|
253
265
|
|
|
254
266
|
#
|
|
255
267
|
################################
|
|
@@ -265,7 +277,7 @@ class Logger:
|
|
|
265
277
|
################################
|
|
266
278
|
# Error messages
|
|
267
279
|
|
|
268
|
-
def ShowError(self, ex: Exception, message: str | None = None, fatal: bool = False):
|
|
280
|
+
def ShowError(self, ex: Exception, message: str | None = None, fatal: bool = False, additionalCallerDepth: int = 0) -> None:
|
|
269
281
|
|
|
270
282
|
'''Show and log error'''
|
|
271
283
|
|
|
@@ -279,9 +291,9 @@ class Logger:
|
|
|
279
291
|
|
|
280
292
|
if message is not None:
|
|
281
293
|
|
|
282
|
-
self.logWriter(logLevel, message, callerDepth=self.DEFAULT_CALLER_DEPTH)
|
|
294
|
+
self.logWriter(logLevel, message, callerDepth=self.DEFAULT_CALLER_DEPTH + additionalCallerDepth)
|
|
283
295
|
|
|
284
|
-
self.logWriter(logLevel, f"{ex}\n{traceback.format_exc()}", callerDepth=self.DEFAULT_CALLER_DEPTH)
|
|
296
|
+
self.logWriter(logLevel, f"{ex}\n{traceback.format_exc()}", callerDepth=self.DEFAULT_CALLER_DEPTH + additionalCallerDepth)
|
|
285
297
|
|
|
286
298
|
#
|
|
287
299
|
################################
|
|
@@ -377,9 +389,9 @@ ToDo list:
|
|
|
377
389
|
|
|
378
390
|
* Logger *
|
|
379
391
|
|
|
380
|
-
- Add option to set date format
|
|
381
|
-
- Add set* functions
|
|
382
392
|
- Configure log format in config file
|
|
393
|
+
- Configure mili sec digits
|
|
394
|
+
- Add set* functions
|
|
383
395
|
|
|
384
396
|
"""
|
|
385
397
|
""" * * * * * * * * * * * * * """
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: MapleX
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0.dev2
|
|
4
4
|
Summary: A Python library for simple logging, json file operations, Maple file format operations, and console color utilities.
|
|
5
5
|
Author: Ryuji Hazama
|
|
6
6
|
Project-URL: PyPI, https://pypi.org/project/MapleX/
|
|
@@ -16,8 +16,8 @@ Classifier: Operating System :: OS Independent
|
|
|
16
16
|
Requires-Python: >=3.12
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: cryptography>=
|
|
20
|
-
Requires-Dist: pydantic>=2.
|
|
19
|
+
Requires-Dist: cryptography>=49.0.0
|
|
20
|
+
Requires-Dist: pydantic>=2.13.4
|
|
21
21
|
Dynamic: license-file
|
|
22
22
|
|
|
23
23
|
# MapleX
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
maplex/__init__.py,sha256=3ZCEFj5gXyDW4h06Sa39QLsLJd8dJN3mMGPnmsUoQUI,1881
|
|
2
|
+
maplex/jsonHandler.py,sha256=HZ4uCUMzs2oaAYWgInc6gzo960q46e7IOk7tTMzqdAE,7445
|
|
3
|
+
maplex/mapleColors.py,sha256=ASg-GstHkyXsq4mVMuFz8Qaq3nQeFayQWcCy9iHzjTs,1543
|
|
4
|
+
maplex/mapleExceptions.py,sha256=zN-GLYNGSWalQ8GiFH-BxRzYhSfbv6V-1O3cA46yAUo,4924
|
|
5
|
+
maplex/mapleLogger.py,sha256=M7djSjf2ZxQP8lWeuLCiDlCP4ALt2NQproO7ybgX3gM,10819
|
|
6
|
+
maplex/mapleTreeEditor.py,sha256=5596bARJWHXyGUeXWRYx9lKSfaZdBmGQLvkF_OiKzZ0,29249
|
|
7
|
+
maplex/utils.py,sha256=TcUdfn9uhk9zwMTxtWgsZ1ZKdc2_i0ysgrksMbzvX1I,603
|
|
8
|
+
maplex/library/logger/__init__.py,sha256=SXTK3CieuahEa-6-eE-JGb6TwxgS7xyMaOjE5PspDbk,447
|
|
9
|
+
maplex/library/logger/config.py,sha256=FkwzcYGXvAZIrVtHWGSIjExsLd_GDwxFqKmSmdNbJyA,14621
|
|
10
|
+
maplex/library/logger/file_handler.py,sha256=nbBTTNl_-iq2i0ooV6tpCP7JbfTiWvqoFkY0QF6vir8,2740
|
|
11
|
+
maplex/library/logger/formatter.py,sha256=aHPk-56uIcEGsHml2Fb1VwI9l97cll0bn_n1gRhs50k,7400
|
|
12
|
+
maplex/library/logger/log_levels.py,sha256=q4NpokbM6vEabLC7OS-JHZgnhbDROk0yHa5-uM3t_Uw,186
|
|
13
|
+
maplex/library/logger/utilities.py,sha256=-IIPsvrebE4K2fP0fIHT-D55463Zkq3M4SlD0dEZINI,2874
|
|
14
|
+
maplex/library/logger/consts/__init__.py,sha256=_C16zebMU2ac0UdIB96S5j8__qLL4cYh8LQ9TAdFb_I,865
|
|
15
|
+
maplex/library/logger/consts/config_keys.py,sha256=qMBJTMSVerprRrgP86sAmmfPF5IyHGsoBFZTW9uqbjU,486
|
|
16
|
+
maplex/library/logger/consts/defaults.py,sha256=sI5dwexy4BBWq6fNwFfPrkWeWuT5OcCMnhM_8i7vo0g,266
|
|
17
|
+
maplex/library/logger/consts/dict_keys.py,sha256=7cDArmYjVn4t9pniT6csV6ByEKmV8Z4SlB-pWFRRgCw,317
|
|
18
|
+
maplex-3.2.0.dev2.dist-info/licenses/LICENSE,sha256=M7R85ReZ2srvowIPO_c9sHI3DV7QmxnLH93esXVhwGI,1068
|
|
19
|
+
maplex-3.2.0.dev2.dist-info/METADATA,sha256=CP3vWjpTPg6h7YkxSdLPsBVLMKayY9kdpfhSkF40IGQ,7389
|
|
20
|
+
maplex-3.2.0.dev2.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
21
|
+
maplex-3.2.0.dev2.dist-info/top_level.txt,sha256=ME8uFV82K0y0KYJrHVTMgc0hEBV67iXXUKsvom7BO5g,7
|
|
22
|
+
maplex-3.2.0.dev2.dist-info/RECORD,,
|
maplex/library/logger/consts.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
CONFIG_KEY = "MapleLogger"
|
|
3
|
-
FUNC = "func"
|
|
4
|
-
CONSOLE = "Console"
|
|
5
|
-
FILE = "File"
|
|
6
|
-
CONSOLE_LOG_LEVEL = "ConsoleLogLevel"
|
|
7
|
-
FILE_LOG_LEVEL = "FileLogLevel"
|
|
8
|
-
MAX_LOG_SIZE = "MaxLogSize"
|
|
9
|
-
FILE_MODE = "FileMode"
|
|
10
|
-
CONFIG_FILE = "configFile"
|
|
11
|
-
WORKING_DIRECTORY = "WorkingDirectory"
|
|
12
|
-
FILE_ENCODING = "FileEncoding"
|
|
13
|
-
TIMESTAMP_FORMAT = "TimestampFormat"
|
|
14
|
-
ALIGN_WIDTH = "AlignWidth"
|
|
15
|
-
GET_LOGGER = "getLogger"
|
|
16
|
-
CONSOLE_ALIGN_WIDTH = "consoleAlignWidth"
|
|
17
|
-
FILE_ALIGN_WIDTH = "fileAlignWidth"
|
|
18
|
-
CONSOLE_FORMAT = "ConsoleFormat"
|
|
19
|
-
FILE_FORMAT = "FileFormat"
|
|
20
|
-
|
|
21
|
-
CALLER_NAME = "CallerName"
|
|
22
|
-
PROCESS_ID = "pid"
|
|
23
|
-
|
|
24
|
-
FILE_FORMAT = '({pid}) {timestamp} [{level}]{func} {callerName}{callerFunc}({callerLine})'
|
|
25
|
-
CONSOLE_FORMAT = '[{level}]{func} {callerFunc}{callerLine}'
|
|
26
|
-
|
|
27
|
-
FILE_MODE_OVERWRITE = 'overwrite'
|
|
28
|
-
FILE_MODE_DAILY = 'daily'
|
maplex-3.1.2.dist-info/RECORD
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
maplex/__init__.py,sha256=DFNo-Ox_Al0KhCfPrFor8yCvBuXexDywHa2nk-KOvoE,1876
|
|
2
|
-
maplex/jsonHandler.py,sha256=HZ4uCUMzs2oaAYWgInc6gzo960q46e7IOk7tTMzqdAE,7445
|
|
3
|
-
maplex/mapleColors.py,sha256=ASg-GstHkyXsq4mVMuFz8Qaq3nQeFayQWcCy9iHzjTs,1543
|
|
4
|
-
maplex/mapleExceptions.py,sha256=zN-GLYNGSWalQ8GiFH-BxRzYhSfbv6V-1O3cA46yAUo,4924
|
|
5
|
-
maplex/mapleLogger.py,sha256=rhSAFkrFt5vsHigvmyXaMp7kOi7LLA_oS5di6uIrYco,10380
|
|
6
|
-
maplex/mapleTreeEditor.py,sha256=5596bARJWHXyGUeXWRYx9lKSfaZdBmGQLvkF_OiKzZ0,29249
|
|
7
|
-
maplex/utils.py,sha256=TcUdfn9uhk9zwMTxtWgsZ1ZKdc2_i0ysgrksMbzvX1I,603
|
|
8
|
-
maplex/library/logger/__init__.py,sha256=TzK7rP_gnljIa_cSpApJgxQBD4huQO9qS5HJGcyuXAI,419
|
|
9
|
-
maplex/library/logger/config.py,sha256=l7YYUv3ZpO3q8Z_7SHGQ6rql8nd1-s5g9SBeZ6gZGi8,10924
|
|
10
|
-
maplex/library/logger/consts.py,sha256=b7fn9TYjJhPgaNPCtYP6f-8SoMGclbRY7TjuyR44kMI,780
|
|
11
|
-
maplex/library/logger/file_handler.py,sha256=nbBTTNl_-iq2i0ooV6tpCP7JbfTiWvqoFkY0QF6vir8,2740
|
|
12
|
-
maplex/library/logger/formatter.py,sha256=ER0vXWctdtETKB4BL3Nj8cDYs2wN00uMW1YCG5FMqVM,7258
|
|
13
|
-
maplex/library/logger/log_levels.py,sha256=q4NpokbM6vEabLC7OS-JHZgnhbDROk0yHa5-uM3t_Uw,186
|
|
14
|
-
maplex/library/logger/utilities.py,sha256=-IIPsvrebE4K2fP0fIHT-D55463Zkq3M4SlD0dEZINI,2874
|
|
15
|
-
maplex-3.1.2.dist-info/licenses/LICENSE,sha256=M7R85ReZ2srvowIPO_c9sHI3DV7QmxnLH93esXVhwGI,1068
|
|
16
|
-
maplex-3.1.2.dist-info/METADATA,sha256=yC9Eqa1v8x4hj9Ufirg839ePavvgpBu3X5DhNL-mnGM,7384
|
|
17
|
-
maplex-3.1.2.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
18
|
-
maplex-3.1.2.dist-info/top_level.txt,sha256=ME8uFV82K0y0KYJrHVTMgc0hEBV67iXXUKsvom7BO5g,7
|
|
19
|
-
maplex-3.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|