xtn-tools-pro 1.0.0.1.8__tar.gz → 1.0.0.2.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {xtn-tools-pro-1.0.0.1.8/xtn_tools_pro.egg-info → xtn-tools-pro-1.0.0.2.0}/PKG-INFO +2 -2
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/setup.py +2 -2
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/db/RedisDB.py +13 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/file_utils.py +9 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/log.py +46 -8
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0/xtn_tools_pro.egg-info}/PKG-INFO +2 -2
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/LICENSE +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/README.md +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/setup.cfg +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/db/MongoDB.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/db/MysqlDB.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/db/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/proxy/XiaoXiangProxy.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/proxy/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/proxy/proxy.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/tools.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/crypto.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/helpers.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/retry.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/sql.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro/utils/time_utils.py +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro.egg-info/SOURCES.txt +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro.egg-info/dependency_links.txt +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro.egg-info/requires.txt +0 -0
- {xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xtn-tools-pro
|
3
|
-
Version: 1.0.0.
|
3
|
+
Version: 1.0.0.2.0
|
4
4
|
Summary: xtn 开发工具
|
5
5
|
Author: xtn
|
6
|
-
Author-email: czw011122@
|
6
|
+
Author-email: czw011122@gmail.com
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
8
8
|
Requires-Python: >=3
|
9
9
|
Description-Content-Type: text/markdown
|
@@ -15,9 +15,9 @@ with open("README.md", "r") as f:
|
|
15
15
|
|
16
16
|
setuptools.setup(
|
17
17
|
name="xtn-tools-pro", # 模块名称
|
18
|
-
version="1.0.0.
|
18
|
+
version="1.0.0.2.0", # 版本
|
19
19
|
author="xtn", # 作者
|
20
|
-
author_email="czw011122@
|
20
|
+
author_email="czw011122@gmail.com", # 作者邮箱
|
21
21
|
description="xtn 开发工具", # 模块简介
|
22
22
|
long_description=long_description, # 模块详细介绍
|
23
23
|
long_description_content_type="text/markdown", # 模块详细介绍格式
|
@@ -121,6 +121,17 @@ class RedisDBPro:
|
|
121
121
|
"""
|
122
122
|
return self._redis.spop(table)
|
123
123
|
|
124
|
+
def sget_count(self, table):
|
125
|
+
"""
|
126
|
+
获取无序集合数量
|
127
|
+
:param table:
|
128
|
+
:return:
|
129
|
+
"""
|
130
|
+
return self._redis.scard(table)
|
131
|
+
|
132
|
+
def get_redis(self):
|
133
|
+
return self._redis
|
134
|
+
|
124
135
|
def incr(self, key):
|
125
136
|
"""
|
126
137
|
对一个键的值进行自增操作
|
@@ -163,6 +174,8 @@ class RedisDBPro:
|
|
163
174
|
return self._redis.delete(table)
|
164
175
|
|
165
176
|
|
177
|
+
|
178
|
+
|
166
179
|
if __name__ == '__main__':
|
167
180
|
pass
|
168
181
|
# r = RedisDBPro(ip="127.0.0.1", port=6379, db=0, user_pass="xtn-kk")
|
@@ -35,6 +35,15 @@ def get_file_check_filename(file_name):
|
|
35
35
|
sanitized_filename = sanitized_filename[:max_length]
|
36
36
|
return sanitized_filename
|
37
37
|
|
38
|
+
def mkdirs_dir(file_path):
|
39
|
+
"""
|
40
|
+
传入一个文件路径创建对应的文件夹,如果某一段不存在则一路创建下去
|
41
|
+
:param file_path:
|
42
|
+
:return:
|
43
|
+
"""
|
44
|
+
directory = os.path.dirname(file_path)
|
45
|
+
if not os.path.exists(directory):
|
46
|
+
os.makedirs(directory)
|
38
47
|
|
39
48
|
if __name__ == '__main__':
|
40
49
|
pass
|
@@ -13,6 +13,7 @@ import sys
|
|
13
13
|
import inspect
|
14
14
|
import logging
|
15
15
|
from logging.handlers import BaseRotatingHandler
|
16
|
+
from xtn_tools_pro.utils.file_utils import mkdirs_dir
|
16
17
|
from xtn_tools_pro.utils.time_utils import get_time_timestamp_to_datestr
|
17
18
|
|
18
19
|
|
@@ -77,7 +78,10 @@ class Log:
|
|
77
78
|
is_write_to_file=False,
|
78
79
|
color=True,
|
79
80
|
mode='a',
|
80
|
-
max_bytes=
|
81
|
+
max_bytes=1024000000,
|
82
|
+
backup_count=0,
|
83
|
+
encoding="utf-8",
|
84
|
+
save_time_log_path=None):
|
81
85
|
"""
|
82
86
|
:param name: log名
|
83
87
|
:param path: log文件存储路径 如 D://xxx.log
|
@@ -89,18 +93,27 @@ class Log:
|
|
89
93
|
:param max_bytes: 每个日志文件的最大字节数
|
90
94
|
:param backup_count: 日志文件保留数量
|
91
95
|
:param encoding: 日志文件编码
|
96
|
+
:param save_time_log_path: 保存时间日志的路径 './logs'
|
92
97
|
|
93
98
|
"""
|
94
99
|
# 创建logger对象
|
95
100
|
self.logger = logging.getLogger(name)
|
96
101
|
# 设置日志等级
|
97
102
|
self.logger.setLevel(log_level.upper())
|
103
|
+
self.save_time_log_path = save_time_log_path
|
104
|
+
if save_time_log_path:
|
105
|
+
# 记录当前的日期,用于之后检查日期是否已经改变
|
106
|
+
self.current_date = get_time_timestamp_to_datestr(format="%Y_%m_%d")
|
107
|
+
# 记录日志文件的路径模板,用于之后创建新的日志文件
|
108
|
+
self.path_template = self.path_template = f"{save_time_log_path}/{{date}}/{name}.log"
|
109
|
+
path = self.path_template.format(date=self.current_date)
|
110
|
+
mkdirs_dir(self.path_template.format(date=self.current_date))
|
98
111
|
|
99
112
|
# 创建日志格式化器
|
100
113
|
# formatter = logging.Formatter('[%(now_datestr)s] [%(levelname)s] [%(func_name)s] - %(message)s') # 原
|
101
114
|
# formatter = logging.Formatter('\033[1m%(now_datestr)s] [%(levelname)s] [%(func_name)s] - %(message)s\033[0m') #加粗
|
102
115
|
formatter = logging.Formatter(
|
103
|
-
'
|
116
|
+
'[%(now_datestr)s] | %(levelname)-8s | [%(func_name)s] - %(message)s') # 加粗对齐
|
104
117
|
|
105
118
|
# formatter = BoldFormatter('[%(now_datestr)s] [%(levelname)s] [%(func_name)s] - %(message)s') # 加粗
|
106
119
|
|
@@ -139,31 +152,53 @@ class Log:
|
|
139
152
|
'CRITICAL': 'bold_red',
|
140
153
|
}
|
141
154
|
color_formatter = ColoredFormatter(
|
142
|
-
'\033[1m%(log_color)s[%(now_datestr)s] | %(levelname)-8s | [%(func_name)s] - %(message)s\033[0m',
|
155
|
+
# '\033[1m%(log_color)s[%(now_datestr)s] | %(levelname)-8s | [%(func_name)s] - %(message)s\033[0m',
|
156
|
+
'%(log_color)s[%(now_datestr)s] | %(levelname)-8s | [%(func_name)s] - %(message)s',
|
143
157
|
log_colors=log_colors) # 加粗对齐
|
144
158
|
# 设置控制台处理器的格式化器为带颜色的格式化器
|
145
159
|
console_handler.setFormatter(color_formatter)
|
146
160
|
except ImportError:
|
147
161
|
pass
|
148
162
|
|
163
|
+
def _get_log_file_path(self):
|
164
|
+
"""获取日志文件的路径,如果日期已经改变就创建一个新的日志文件"""
|
165
|
+
if not self.save_time_log_path: return
|
166
|
+
date = get_time_timestamp_to_datestr(format="%Y_%m_%d")
|
167
|
+
if date != self.current_date:
|
168
|
+
# 日期已经改变,更新当前的日期
|
169
|
+
self.current_date = date
|
170
|
+
# 更新文件处理器的文件路径
|
171
|
+
path = self.path_template.format(date=date)
|
172
|
+
mkdirs_dir(path)
|
173
|
+
for handler in self.logger.handlers:
|
174
|
+
if isinstance(handler, RotatingFileHandler):
|
175
|
+
handler.baseFilename = path
|
176
|
+
handler.doRollover()
|
177
|
+
break
|
178
|
+
|
149
179
|
def debug(self, message):
|
150
180
|
# 记录DEBUG级别的日志
|
181
|
+
self._get_log_file_path()
|
151
182
|
self.logger.debug(message, extra=self._get_caller_name_extra())
|
152
183
|
|
153
184
|
def info(self, message):
|
154
185
|
# 记录INFO级别的日志
|
186
|
+
self._get_log_file_path()
|
155
187
|
self.logger.info(message, extra=self._get_caller_name_extra())
|
156
188
|
|
157
189
|
def warning(self, message):
|
158
190
|
# 记录WARNING级别的日志
|
191
|
+
self._get_log_file_path()
|
159
192
|
self.logger.warning(message, extra=self._get_caller_name_extra())
|
160
193
|
|
161
194
|
def error(self, message):
|
162
195
|
# 记录ERROR级别的日志
|
196
|
+
self._get_log_file_path()
|
163
197
|
self.logger.error(message, extra=self._get_caller_name_extra())
|
164
198
|
|
165
199
|
def critical(self, message):
|
166
200
|
# 记录CRITICAL级别的日志
|
201
|
+
self._get_log_file_path()
|
167
202
|
self.logger.critical(message, extra=self._get_caller_name_extra())
|
168
203
|
|
169
204
|
def _get_caller_name_extra(self):
|
@@ -185,8 +220,11 @@ class Log:
|
|
185
220
|
if __name__ == '__main__':
|
186
221
|
pass
|
187
222
|
logger = Log('mylogger', './xxx.log', log_level='DEBUG', is_write_to_console=True, is_write_to_file=True,
|
188
|
-
color=True, mode='a',
|
189
|
-
|
190
|
-
|
191
|
-
logger.
|
192
|
-
logger.
|
223
|
+
color=True, mode='a', save_time_log_path='./logs')
|
224
|
+
# import time
|
225
|
+
# while True:
|
226
|
+
# logger.debug("debug message")
|
227
|
+
# logger.info("info level message")
|
228
|
+
# logger.warning("warning level message")
|
229
|
+
# logger.critical("critical level message 你好")
|
230
|
+
# time.sleep(1)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xtn-tools-pro
|
3
|
-
Version: 1.0.0.
|
3
|
+
Version: 1.0.0.2.0
|
4
4
|
Summary: xtn 开发工具
|
5
5
|
Author: xtn
|
6
|
-
Author-email: czw011122@
|
6
|
+
Author-email: czw011122@gmail.com
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
8
8
|
Requires-Python: >=3
|
9
9
|
Description-Content-Type: text/markdown
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{xtn-tools-pro-1.0.0.1.8 → xtn-tools-pro-1.0.0.2.0}/xtn_tools_pro.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|