File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+ """
4+ @author: 闲欢
5+ """
6+ from loguru import logger
7+
8+ logger .debug ('this is a debug message' )
9+
10+ logger .add ('hello.log' )
11+
12+ logger .debug ('i am in log file' )
13+
14+ id = logger .add ('world.log' , format = "{time} | {level} | {message}" , level = "INFO" )
15+ logger .info ('this is a debug message' )
16+ logger .remove (id )
17+ logger .info ('this is another debug message' )
18+ logger .add ('runtime.log' )
19+ logger .info ('this is an debug message' )
20+
21+ # 超过200M就新生成一个文件
22+ logger .add ("size.log" , rotation = "200 MB" )
23+ # 每天中午12点生成一个新文件
24+ logger .add ("time.log" , rotation = "12:00" )
25+ # 一周生成一个新文件
26+ logger .add ("size.log" , rotation = "1 week" )
27+
28+ @logger .catch
29+ def a_function (x ):
30+ return 1 / x
31+
32+ a_function (0 )
33+
34+
35+
36+ def b_function1 (x ):
37+ try :
38+ return 1 / x
39+ except ZeroDivisionError :
40+ logger .exception ("exception!!!" )
41+
42+ b_function1 (0 )
You can’t perform that action at this time.
0 commit comments