-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_test.py
62 lines (51 loc) · 2.12 KB
/
demo_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# coding:utf-8
# author caturbhuja
# date 2020/11/25 2:43 下午
# wechat chending2012
from dlog import DLog
from dlog_pack.dlog import DLog
if __name__ == '__main__':
# ----------- 设定日志目录绝对路径(强烈建议) -----------
# 如果没有指定日志目录,则日志目录在 现在现在的执行文件的平级目录下。
import os
RootPath = os.path.dirname(os.path.realpath(__file__))
log = DLog(log_dir_path=RootPath, multiprocess_safe=False).get_log
log.info('nice')
log.warning('nice')
log.error('nice')
# ----------- 添加新的日志类型 -----------
new_log_file_list = [{"file_name": "access", "log_level": "info"}, ]
log1 = DLog(new_log_file_list=new_log_file_list).get_log
log1.access('access my lord')
# ----------- 修改日志格式 -----------
new_log_file_list = [
{"file_name": "access", "log_level": "warning", "format": "%(levelname)s: %(message)s"},
{"file_name": "info", "log_level": "info", "format": "%(asctime)s: %(message)s"},
]
log5 = DLog(new_log_file_list=new_log_file_list)
print(log5.show_log_config) # 显示日志配置文件
log5 = log5.get_log
log5.info('change my info format')
log5.access('warning my info format')
# ----------- 设置日志分割大小为10Mb,备份数量 7 份-----------
log4 = DLog(max_bytes=10, backup_count=7).get_log
log4.info('nice')
log4.warning('nice')
log4.error('nice')
# ----------- 开启单例模式 -----------
log2 = DLog(singleton=True).get_log
log2.info('nice')
log2.warning('nice')
log2.error('nice')
# ----------- 一般方式 -----------
log3 = DLog().get_log
log3.info('nice')
log3.warning('nice')
log3.error('nice')
# ----------- 关闭进程安全, -----------
# 目前一直单例模式下,开启进程安全,日志会报获取不到进程锁的问题,但是不影响使用
RootPath = os.path.dirname(os.path.realpath(__file__))
log = DLog(log_dir_path=RootPath, multiprocess_safe=False).get_log
log.info('nice')
log.warning('nice')
log.error('nice')