29 lines
666 B
Python
29 lines
666 B
Python
|
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")
|
||
|
|