Skip to content

Commit 368e5b0

Browse files
committed
提交代码
1 parent 9605ade commit 368e5b0

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

xianhuan/.DS_Store

2 KB
Binary file not shown.

xianhuan/loguru/logurustudy.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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)

0 commit comments

Comments
 (0)