无法自定义日志 rotation 时添加的时间格式,修改 loguru 的源代码来实现
找到python环境下的logoru文件夹。修改文件
anaconda/envslib/python3.8/site-packages/loguru/_file_sink.py
def generate_rename_path(root, ext, creation_time):
creation_datetime = datetime.fromtimestamp(creation_time)
date = FileDateFormatter(creation_datetime)
renamed_path = "{}.{:%Y%m%d}{}".format(root, date, ext)
counter = 1
while os.path.exists(renamed_path):
counter += 1
renamed_path = "{}.{:%Y%m%d}.{}{}".format(root, date, counter, ext)
return renamed_path
- root :不带后缀名的日志文件
/home_log/access
- date:当前时间
默认格式:%Y-%m-%d_%H-%M-%S_%f - ext:后缀名
.log
修改date的格式化方式
注意“:”不能少
修改前文件名:
access.log
备份文件名:
access.20220610.log.zip



