xtn-tools-pro 1.0.1.1.9__py3-none-any.whl → 1.0.1.2.1__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.
- xtn_tools_pro/utils/log.py +22 -4
- {xtn_tools_pro-1.0.1.1.9.dist-info → xtn_tools_pro-1.0.1.2.1.dist-info}/METADATA +1 -1
- {xtn_tools_pro-1.0.1.1.9.dist-info → xtn_tools_pro-1.0.1.2.1.dist-info}/RECORD +7 -7
- {xtn_tools_pro-1.0.1.1.9.dist-info → xtn_tools_pro-1.0.1.2.1.dist-info}/LICENSE +0 -0
- {xtn_tools_pro-1.0.1.1.9.dist-info → xtn_tools_pro-1.0.1.2.1.dist-info}/WHEEL +0 -0
- {xtn_tools_pro-1.0.1.1.9.dist-info → xtn_tools_pro-1.0.1.2.1.dist-info}/entry_points.txt +0 -0
- {xtn_tools_pro-1.0.1.1.9.dist-info → xtn_tools_pro-1.0.1.2.1.dist-info}/top_level.txt +0 -0
xtn_tools_pro/utils/log.py
CHANGED
@@ -72,6 +72,17 @@ class BoldFormatter(logging.Formatter):
|
|
72
72
|
return "\033[1m" + result + "\033[0m"
|
73
73
|
|
74
74
|
|
75
|
+
def get_caller_script_path():
|
76
|
+
# 获取调用栈列表
|
77
|
+
stack = inspect.stack()
|
78
|
+
# 遍历调用栈,找到第一个非本模块的调用者
|
79
|
+
for frame_info in stack:
|
80
|
+
filename = frame_info.filename
|
81
|
+
if filename != __file__: # 排除日志模块自身的路径
|
82
|
+
return os.path.abspath(filename)
|
83
|
+
return os.path.abspath(__file__) # 默认返回当前模块路径(理论上不会执行到这里)
|
84
|
+
|
85
|
+
|
75
86
|
class Log:
|
76
87
|
def __init__(self, name, path=None, log_level='DEBUG',
|
77
88
|
is_write_to_console=True,
|
@@ -102,13 +113,20 @@ class Log:
|
|
102
113
|
self.logger.setLevel(log_level.upper())
|
103
114
|
self.save_time_log_path = save_time_log_path
|
104
115
|
if save_time_log_path:
|
116
|
+
# 获取调用文件的所在文件夹路径
|
117
|
+
run_py_path = os.path.dirname(get_caller_script_path())
|
105
118
|
# 记录当前的日期,用于之后检查日期是否已经改变
|
106
119
|
self.current_date = get_time_timestamp_to_datestr(format="%Y_%m_%d")
|
107
120
|
# 记录日志文件的路径模板,用于之后创建新的日志文件
|
108
|
-
self.path_template =
|
121
|
+
self.path_template = f"logs/{{date}}/{name}.log"
|
109
122
|
path = self.path_template.format(date=self.current_date)
|
123
|
+
# print(path)
|
110
124
|
if is_write_to_file:
|
111
|
-
|
125
|
+
mkdirs_dir_log_dirname = os.path.join(run_py_path, os.path.dirname(path))
|
126
|
+
self.mkdirs_dir_log_path = os.path.join(run_py_path, path)
|
127
|
+
# print(mkdirs_dir_log_dirname)
|
128
|
+
# print(mkdirs_dir_log_path)
|
129
|
+
mkdirs_dir(self.mkdirs_dir_log_path)
|
112
130
|
|
113
131
|
# 创建日志格式化器
|
114
132
|
# formatter = logging.Formatter('[%(now_datestr)s] [%(levelname)s] [%(func_name)s] - %(message)s') # 原
|
@@ -130,7 +148,7 @@ class Log:
|
|
130
148
|
# 判断是否要写入文件
|
131
149
|
if is_write_to_file:
|
132
150
|
# 创建文件处理器
|
133
|
-
file_handler = RotatingFileHandler(
|
151
|
+
file_handler = RotatingFileHandler(self.mkdirs_dir_log_path, mode=mode, max_bytes=max_bytes,
|
134
152
|
backup_count=backup_count, encoding=encoding)
|
135
153
|
# 设置文件处理器的格式化器
|
136
154
|
file_handler.setFormatter(formatter)
|
@@ -229,4 +247,4 @@ if __name__ == '__main__':
|
|
229
247
|
logger.info("info level message")
|
230
248
|
logger.warning("warning level message")
|
231
249
|
logger.critical("critical level message 你好")
|
232
|
-
time.sleep(1)
|
250
|
+
# time.sleep(1)
|
@@ -56,15 +56,15 @@ xtn_tools_pro/utils/__init__.py,sha256=I1_n_NP23F2lBqlF4EOlnOdLYxM8M4pbn63UhJN1h
|
|
56
56
|
xtn_tools_pro/utils/crypto.py,sha256=fyqno82Tw8LeF5i8YiEpjPI3oswsqTeWE5Lc9M2ef68,4603
|
57
57
|
xtn_tools_pro/utils/file_utils.py,sha256=obaBP7CaBCsXxzqGeWzV2l0yw7vicgKOaXzmpMV8ips,2567
|
58
58
|
xtn_tools_pro/utils/helpers.py,sha256=0CTMY7wfSQR_DC9-v1lkKQLpWcB1FL9V_kw_5DOcZ40,4454
|
59
|
-
xtn_tools_pro/utils/log.py,sha256=
|
59
|
+
xtn_tools_pro/utils/log.py,sha256=DTUWwi5pvZrwwq94odGnR0JBhfStrc6SxcJREqf2Ls4,11031
|
60
60
|
xtn_tools_pro/utils/retry.py,sha256=0wjHsR5DBBKpv4naMfxiky8kprrZes4WURIfFQ4H708,1657
|
61
61
|
xtn_tools_pro/utils/set_data.py,sha256=BzCLbEDO83csDHBey8kP7SoE6kx6EjqE7OqRBY7k82s,17608
|
62
62
|
xtn_tools_pro/utils/shell.py,sha256=s6sJedxLLQokcI1hF5YSD3qgGUPK0brNcP-D3-yv54I,3790
|
63
63
|
xtn_tools_pro/utils/sql.py,sha256=EAKzbkZP7Q09j15Gm6o0_uq0qgQmcCQT6EAawbpp4v0,6263
|
64
64
|
xtn_tools_pro/utils/time_utils.py,sha256=TUtzG61PeVYXhaQd6pBrXAdlz7tBispNIRQRcGhE2No,4859
|
65
|
-
xtn_tools_pro-1.0.1.1.
|
66
|
-
xtn_tools_pro-1.0.1.1.
|
67
|
-
xtn_tools_pro-1.0.1.1.
|
68
|
-
xtn_tools_pro-1.0.1.1.
|
69
|
-
xtn_tools_pro-1.0.1.1.
|
70
|
-
xtn_tools_pro-1.0.1.1.
|
65
|
+
xtn_tools_pro-1.0.1.2.1.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
66
|
+
xtn_tools_pro-1.0.1.2.1.dist-info/METADATA,sha256=_BpF7-T-W_A4cqOI5FP9W1LOejUJLl2t68ATZ_18Vrc,545
|
67
|
+
xtn_tools_pro-1.0.1.2.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
68
|
+
xtn_tools_pro-1.0.1.2.1.dist-info/entry_points.txt,sha256=t8CtXWOgw7nRDW3XNlZh8MT_P4l8EzsFnyWi5b3ovrc,68
|
69
|
+
xtn_tools_pro-1.0.1.2.1.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
|
70
|
+
xtn_tools_pro-1.0.1.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|