简体   繁体   中英

How to create a path for saving the log file? And save in separate log file each time?

now I need to save a log file but don't know how to save the log file to the desired path. How to make the line?

I have used this but there appears a bug. Please help! Thanks!

import logging
import logging.config

logging.basicConfig(format='%(asctime)s %(message)s', filename='daily_report.log', level=logging.INFO)
logging.config.fileConfig('C:/.../.../.../daily_report.log', disable_existing_loggers=False)

I have found my own solution to add directly the path into 'filename=...' of basicConfig.

The next problem is how to save the log file into a separate file with the datetime format on file'sname

Try running

logging.FileHandler("C:/.../.../.../daily_report.log")

after the .basicConfig

I have found the solution just replace directly to the first line code.

logging.basicConfig(format='%(asctime)s %(message)s', filename="C:/.../.../.../daily_report.log"), level=logging.INFO)

The next question is how to produce a separate file log for each time run the code?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM