更新日志输出路径

This commit is contained in:
Yorusora 2025-01-10 15:17:39 +08:00
parent 883ea33876
commit fc7abf9208
2 changed files with 5 additions and 3 deletions

4
.gitignore vendored
View File

@ -253,7 +253,7 @@ ipython_config.py
# Remove previous ipynb_checkpoints # Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/ # git rm -r .ipynb_checkpoints/
data/* data/*
history/* logs/*
.idea/* .idea/*
!./data !./data
!./history !./logs

View File

@ -39,7 +39,9 @@ plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.NOTSET) logger.setLevel(logging.NOTSET)
realtime = time.strftime('%Y%m%d', time.localtime(time.time())) realtime = time.strftime('%Y%m%d', time.localtime(time.time()))
fh = logging.FileHandler(Path("history") / (realtime + ".log"), mode='a') if not os.path.exists(Path("logs")):
os.makedirs(Path("logs"))
fh = logging.FileHandler(Path("logs") / (realtime + ".log"), mode='a')
fh.setLevel(logging.NOTSET) fh.setLevel(logging.NOTSET)
fh.setFormatter(logging.Formatter("%(asctime)s: %(message)s")) fh.setFormatter(logging.Formatter("%(asctime)s: %(message)s"))
logger.addHandler(fh) logger.addHandler(fh)