使用中文日志 调整一些业务逻辑
This commit is contained in:
28
log.py
Normal file
28
log.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import time
|
||||
|
||||
|
||||
|
||||
# 同一个进程中所有调用这个文件的 .py 文件都使用这个变量
|
||||
_log_fp=None
|
||||
|
||||
def _time():
|
||||
return '['+time.strftime("%Y-%m-%d %H:%M:%S")+']'
|
||||
|
||||
def myprint_dec(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
# 在这里添加额外的功能
|
||||
# print(_time(), str(e),file=_log_fp)
|
||||
print(_time(), *args, **kwargs)
|
||||
kwargs["file"]=_log_fp
|
||||
result = func(_time(),*args, **kwargs)
|
||||
_log_fp.flush()
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
myprint=myprint_dec(print)
|
||||
|
||||
def log_init(file_name:str):
|
||||
global _log_fp
|
||||
if _log_fp is None:
|
||||
_log_fp=open(file_name,mode="w+",encoding="utf-8")
|
||||
|
Reference in New Issue
Block a user