beans-logging 6.0.2__py3-none-any.whl → 7.0.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.
- beans_logging/__init__.py +6 -6
- beans_logging/__version__.py +1 -1
- beans_logging/_builder.py +154 -0
- beans_logging/_constants.py +30 -0
- beans_logging/_core.py +295 -0
- beans_logging/_intercept.py +106 -0
- beans_logging/auto.py +3 -12
- beans_logging/config.py +186 -0
- beans_logging/filters.py +37 -20
- beans_logging/formats.py +20 -4
- beans_logging/{rotation.py → rotators.py} +20 -14
- beans_logging/schemas.py +129 -159
- beans_logging/sinks.py +11 -2
- {beans_logging-6.0.2.dist-info → beans_logging-7.0.0.dist-info}/METADATA +80 -61
- beans_logging-7.0.0.dist-info/RECORD +18 -0
- beans_logging/_base.py +0 -660
- beans_logging/_consts.py +0 -18
- beans_logging/_handlers.py +0 -40
- beans_logging/_utils.py +0 -99
- beans_logging-6.0.2.dist-info/RECORD +0 -17
- {beans_logging-6.0.2.dist-info → beans_logging-7.0.0.dist-info}/WHEEL +0 -0
- {beans_logging-6.0.2.dist-info → beans_logging-7.0.0.dist-info}/licenses/LICENSE.txt +0 -0
- {beans_logging-6.0.2.dist-info → beans_logging-7.0.0.dist-info}/top_level.txt +0 -0
beans_logging/_handlers.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import logging
|
|
3
|
-
from logging import LogRecord
|
|
4
|
-
|
|
5
|
-
from loguru import logger
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class InterceptHandler(logging.Handler):
|
|
9
|
-
"""A handler class that intercepts logs from standard logging and redirects them to loguru logger.
|
|
10
|
-
|
|
11
|
-
Inherits:
|
|
12
|
-
logging.Handler: Handler class from standard logging.
|
|
13
|
-
|
|
14
|
-
Overrides:
|
|
15
|
-
emit(): Handle intercepted log record.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
def emit(self, record: LogRecord):
|
|
19
|
-
"""
|
|
20
|
-
Handle intercepted log record.
|
|
21
|
-
|
|
22
|
-
Args:
|
|
23
|
-
record (LogRecord, required): Log needs to be handled.
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
# Get corresponding Loguru level if it exists
|
|
27
|
-
try:
|
|
28
|
-
_level = logger.level(record.levelname).name
|
|
29
|
-
except ValueError:
|
|
30
|
-
_level = record.levelno
|
|
31
|
-
|
|
32
|
-
# Find caller from where originated the logged message
|
|
33
|
-
_frame, _depth = sys._getframe(6), 6
|
|
34
|
-
while _frame and _frame.f_code.co_filename == logging.__file__:
|
|
35
|
-
_frame = _frame.f_back
|
|
36
|
-
_depth += 1
|
|
37
|
-
|
|
38
|
-
logger.opt(depth=_depth, exception=record.exc_info).log(
|
|
39
|
-
_level, record.getMessage()
|
|
40
|
-
)
|
beans_logging/_utils.py
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
import copy
|
|
4
|
-
import errno
|
|
5
|
-
|
|
6
|
-
from loguru import logger
|
|
7
|
-
import pydantic
|
|
8
|
-
|
|
9
|
-
if "2.0.0" <= pydantic.__version__:
|
|
10
|
-
from pydantic import validate_call
|
|
11
|
-
else:
|
|
12
|
-
from pydantic import validate_arguments as validate_call
|
|
13
|
-
|
|
14
|
-
from ._consts import WarnEnum
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@validate_call
|
|
18
|
-
def create_dir(create_dir: str, warn_mode: WarnEnum = WarnEnum.DEBUG):
|
|
19
|
-
"""Create directory if `create_dir` doesn't exist.
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
create_dir (str, required): Create directory path.
|
|
23
|
-
warn_mode (str, optional): Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'.
|
|
24
|
-
Defaults to "DEBUG".
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
if not os.path.isdir(create_dir):
|
|
28
|
-
try:
|
|
29
|
-
_message = f"Creaing '{create_dir}' directory..."
|
|
30
|
-
if warn_mode == WarnEnum.ALWAYS:
|
|
31
|
-
logger.info(_message)
|
|
32
|
-
elif warn_mode == WarnEnum.DEBUG:
|
|
33
|
-
logger.debug(_message)
|
|
34
|
-
|
|
35
|
-
os.makedirs(create_dir)
|
|
36
|
-
except OSError as err:
|
|
37
|
-
if err.errno == errno.EEXIST:
|
|
38
|
-
logger.debug(f"'{create_dir}' directory already exists!")
|
|
39
|
-
else:
|
|
40
|
-
logger.error(f"Failed to create '{create_dir}' directory!")
|
|
41
|
-
raise
|
|
42
|
-
|
|
43
|
-
_message = f"Successfully created '{create_dir}' directory."
|
|
44
|
-
if warn_mode == WarnEnum.ALWAYS:
|
|
45
|
-
logger.success(_message)
|
|
46
|
-
elif warn_mode == WarnEnum.DEBUG:
|
|
47
|
-
logger.debug(_message)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@validate_call
|
|
51
|
-
def deep_merge(dict1: dict, dict2: dict) -> dict:
|
|
52
|
-
"""Return a new dictionary that's the result of a deep merge of two dictionaries.
|
|
53
|
-
If there are conflicts, values from `dict2` will overwrite those in `dict1`.
|
|
54
|
-
|
|
55
|
-
Args:
|
|
56
|
-
dict1 (dict, required): The base dictionary that will be merged.
|
|
57
|
-
dict2 (dict, required): The dictionary to merge into `dict1`.
|
|
58
|
-
|
|
59
|
-
Returns:
|
|
60
|
-
dict: The merged dictionary.
|
|
61
|
-
"""
|
|
62
|
-
|
|
63
|
-
_merged = copy.deepcopy(dict1)
|
|
64
|
-
for _key, _val in dict2.items():
|
|
65
|
-
if (
|
|
66
|
-
_key in _merged
|
|
67
|
-
and isinstance(_merged[_key], dict)
|
|
68
|
-
and isinstance(_val, dict)
|
|
69
|
-
):
|
|
70
|
-
_merged[_key] = deep_merge(_merged[_key], _val)
|
|
71
|
-
else:
|
|
72
|
-
_merged[_key] = copy.deepcopy(_val)
|
|
73
|
-
|
|
74
|
-
return _merged
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def get_default_logs_dir() -> str:
|
|
78
|
-
"""Return default logs directory path (current working directory + 'logs').
|
|
79
|
-
|
|
80
|
-
Returns:
|
|
81
|
-
str: Default logs directory path.
|
|
82
|
-
"""
|
|
83
|
-
|
|
84
|
-
return os.path.join(os.getcwd(), "logs")
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def get_app_name() -> str:
|
|
88
|
-
"""Return application name (sys.argv[0]).
|
|
89
|
-
|
|
90
|
-
Returns:
|
|
91
|
-
str: Application name.
|
|
92
|
-
"""
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
os.path.splitext(os.path.basename(sys.argv[0]))[0]
|
|
96
|
-
.strip()
|
|
97
|
-
.replace(" ", "-")
|
|
98
|
-
.lower()
|
|
99
|
-
)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
beans_logging/__init__.py,sha256=Ax1f3I26MSEorCBnkPVcuzEWN7IoJZuzPdVjCukvUv0,272
|
|
2
|
-
beans_logging/__version__.py,sha256=lze97Y7ToUnpENKGAhOoSKx1zlZQe6ZfCSr8M50_K1g,22
|
|
3
|
-
beans_logging/_base.py,sha256=fKwGgtkbUzg2Wtfb5XwIGF5UU56iPOT-R6OD3wqIBws,24645
|
|
4
|
-
beans_logging/_consts.py,sha256=OqSvH2IvsUSbvIgthHeiv92i9CHXKYvO-PCb_DsMANI,320
|
|
5
|
-
beans_logging/_handlers.py,sha256=cz2jcJR0MuVHWWNRAFT617njC_18Q56lNcgKIxLmFys,1106
|
|
6
|
-
beans_logging/_utils.py,sha256=Vk8UT2mPTanP4KuLnxKk6Pv-Nr8iWDom0TwCxHb5EhA,2757
|
|
7
|
-
beans_logging/auto.py,sha256=YQMfmWK6mFEwqabhimj8ZA_yStKZCDQEvteKv2UIbEA,494
|
|
8
|
-
beans_logging/filters.py,sha256=iikVBMIhAF_DP1F0X0GJ7GUOvP-JdcH_CxAsYuz0UxM,3343
|
|
9
|
-
beans_logging/formats.py,sha256=WTIDP0uJL9J9bcFZ2_Qe8zlw_l4SrE2k2agPLvrjfMM,1324
|
|
10
|
-
beans_logging/rotation.py,sha256=t-ORXq7x4tDbvz8XMjCCuDZ6cUApcu3SBQzfgTwHQU8,2110
|
|
11
|
-
beans_logging/schemas.py,sha256=CBaztXAnoqKiL3poLz0ymR8c0EdqKo4rJ_K4kXwDqjo,5631
|
|
12
|
-
beans_logging/sinks.py,sha256=t2U4v95H_tV2ci6YS8aKCnTUKVRxEcsLnB55qn4wyrQ,331
|
|
13
|
-
beans_logging-6.0.2.dist-info/licenses/LICENSE.txt,sha256=CUTK-r0BWIg1r0bBiemAcMhakgV0N7HuRhw6rQ-A9A4,1074
|
|
14
|
-
beans_logging-6.0.2.dist-info/METADATA,sha256=E56H2f4nvUltwTr-k3ZfTrTsdeleUpGcb0FmtvaDInk,12652
|
|
15
|
-
beans_logging-6.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
-
beans_logging-6.0.2.dist-info/top_level.txt,sha256=lx8JEqYGNha1sYbVrTtMo2Z01A7Shq8hX6bfsuKLTG8,14
|
|
17
|
-
beans_logging-6.0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|