日志文件配置(指定文件夹)

cur_path = os.path.split(__file__)[0]

up_path  = os.path.split(cur_path)[0]

filename = tm.strftime('%Y%m%d', tm.localtime(tm.time()))
LOG_DIR = os.path.join(cur_path, 'logs')

if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

log_path = os.path.join(LOG_DIR, '%s.txt' % filename)
logging.basicConfig(level=logging.INFO,
                format='%(asctime)s | %(levelname)-5s | %(filename)s:%(lineno)s:%(funcName)s | %(message)s',
                filename=log_path,
                filemode='a+')
原文地址:https://www.cnblogs.com/Hale-wang/p/12010752.html