shancx 1.3__py3-none-any.whl → 1.50__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.
- shancx/__init__.py +35 -0
- shancx/util_log.py +33 -0
- {shancx-1.3.dist-info → shancx-1.50.dist-info}/METADATA +5 -3
- shancx-1.50.dist-info/RECORD +7 -0
- shancx-1.3.dist-info/RECORD +0 -6
- {shancx-1.3.dist-info → shancx-1.50.dist-info}/WHEEL +0 -0
- {shancx-1.3.dist-info → shancx-1.50.dist-info}/top_level.txt +0 -0
shancx/__init__.py
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# @Time : 2023/09/27 下午8:52
|
|
4
|
+
# @Author : shanchangxi
|
|
5
|
+
# @File : util_log.py
|
|
1
6
|
import time
|
|
7
|
+
import logging # 引入logging模块
|
|
8
|
+
from logging import handlers
|
|
9
|
+
# from util.util_dir import *
|
|
10
|
+
|
|
11
|
+
# 第一步,创建一个logger
|
|
12
|
+
loggers = logging.getLogger()
|
|
13
|
+
loggers.setLevel(logging.INFO) # Log等级开关
|
|
14
|
+
|
|
15
|
+
# 第二步,创建一个handler,用于写入日志文件
|
|
16
|
+
log_name = 'project_tim_tor.log'
|
|
17
|
+
logfile = log_name
|
|
18
|
+
|
|
19
|
+
time_rotating_file_handler = handlers.TimedRotatingFileHandler(filename=logfile, when='D', encoding='utf-8')
|
|
20
|
+
time_rotating_file_handler.setLevel(logging.INFO) # 输出到file的log等级的开关
|
|
21
|
+
|
|
22
|
+
# 第三步,定义handler的输出格式
|
|
23
|
+
formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
|
|
24
|
+
time_rotating_file_handler.setFormatter(formatter)
|
|
25
|
+
|
|
26
|
+
# 第四步,将handler添加到logger里面
|
|
27
|
+
loggers.addHandler(time_rotating_file_handler)
|
|
28
|
+
|
|
29
|
+
# 如果需要同時需要在終端上輸出,定義一個streamHandler
|
|
30
|
+
print_handler = logging.StreamHandler() # 往屏幕上输出
|
|
31
|
+
print_handler.setFormatter(formatter) # 设置屏幕上显示的格式
|
|
32
|
+
loggers.addHandler(print_handler)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
2
36
|
|
|
3
37
|
def tim_tor(func):
|
|
4
38
|
def wrapper(*args, **kwargs):
|
|
@@ -6,5 +40,6 @@ def tim_tor(func):
|
|
|
6
40
|
result = func(*args, **kwargs)
|
|
7
41
|
end_time = time.time()
|
|
8
42
|
print(f"{func.__name__} took {end_time - start_time:.4f} seconds")
|
|
43
|
+
loggers.info(f"{func.__name__} took {end_time - start_time:.4f} seconds")
|
|
9
44
|
return result
|
|
10
45
|
return wrapper
|
shancx/util_log.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
#!/usr/bin/python
|
|
3
|
+
# -*- coding: utf-8 -*-
|
|
4
|
+
# @Time : 2023/09/27 下午8:52
|
|
5
|
+
# @Author : shanchangxi
|
|
6
|
+
# @File : util_log.py
|
|
7
|
+
|
|
8
|
+
import logging # 引入logging模块
|
|
9
|
+
from logging import handlers
|
|
10
|
+
# from util.util_dir import *
|
|
11
|
+
|
|
12
|
+
# 第一步,创建一个logger
|
|
13
|
+
logger = logging.getLogger()
|
|
14
|
+
logger.setLevel(logging.INFO) # Log等级开关
|
|
15
|
+
|
|
16
|
+
# 第二步,创建一个handler,用于写入日志文件
|
|
17
|
+
log_name = 'project.log'
|
|
18
|
+
logfile = log_name
|
|
19
|
+
|
|
20
|
+
time_rotating_file_handler = handlers.TimedRotatingFileHandler(filename=logfile, when='D', encoding='utf-8')
|
|
21
|
+
time_rotating_file_handler.setLevel(logging.INFO) # 输出到file的log等级的开关
|
|
22
|
+
|
|
23
|
+
# 第三步,定义handler的输出格式
|
|
24
|
+
formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
|
|
25
|
+
time_rotating_file_handler.setFormatter(formatter)
|
|
26
|
+
|
|
27
|
+
# 第四步,将handler添加到logger里面
|
|
28
|
+
logger.addHandler(time_rotating_file_handler)
|
|
29
|
+
|
|
30
|
+
# 如果需要同時需要在終端上輸出,定義一個streamHandler
|
|
31
|
+
print_handler = logging.StreamHandler() # 往屏幕上输出
|
|
32
|
+
print_handler.setFormatter(formatter) # 设置屏幕上显示的格式
|
|
33
|
+
logger.addHandler(print_handler)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: shancx
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.50
|
|
4
4
|
Summary: A simple timer decorator
|
|
5
5
|
Home-page: https://gitee.com/shancx
|
|
6
6
|
Author: Your Name
|
|
@@ -17,5 +17,7 @@ A simple Python package that provides a timer decorator to measure the execution
|
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
pip install
|
|
20
|
+
|
|
21
|
+
pip install shancx
|
|
22
|
+
|
|
23
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
my_timer_decorator/__init__.py,sha256=ur0N4vwlv-LfYOCph5A8g6H8aFxxc9EhJdG9sxpa-SY,303
|
|
2
|
+
shancx/__init__.py,sha256=SzIagtqAHBQycqU3mp6jsKqf1JgTBTkY8YHAMoPKKs0,1596
|
|
3
|
+
shancx/util_log.py,sha256=bGu-oCU7hozBBZJB6oDGj9XDDsz5GJVe8ZfJtx5pddA,1204
|
|
4
|
+
shancx-1.50.dist-info/METADATA,sha256=uH2IZ1liCElE12lQebThW45F6Ivn54oGt6usY5srua8,572
|
|
5
|
+
shancx-1.50.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
6
|
+
shancx-1.50.dist-info/top_level.txt,sha256=akfCS1vKWz3pNmEN_yN9ZiGp-60IQY5ET38mRx_i_-4,7
|
|
7
|
+
shancx-1.50.dist-info/RECORD,,
|
shancx-1.3.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
my_timer_decorator/__init__.py,sha256=ur0N4vwlv-LfYOCph5A8g6H8aFxxc9EhJdG9sxpa-SY,303
|
|
2
|
-
shancx/__init__.py,sha256=tr0WT0UyNk-z6-n7qxaRvE_JcrOLA1Oisi83XHzwGzo,295
|
|
3
|
-
shancx-1.3.dist-info/METADATA,sha256=6N2XDSBNqaaXHdjNTbUxPmcCqmWTq5fUYoLqVs1iV6c,583
|
|
4
|
-
shancx-1.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
5
|
-
shancx-1.3.dist-info/top_level.txt,sha256=akfCS1vKWz3pNmEN_yN9ZiGp-60IQY5ET38mRx_i_-4,7
|
|
6
|
-
shancx-1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|