python日志log

2018-10-17  本文已影响9人  曦宝
# -*- coding: utf-8 -*-

# this is a simple example
import logging
import datetime

# define the log file, file mode and logging level
logging.basicConfig(filename='example.log', filemode="w", level=logging.DEBUG)
logging.info(datetime.datetime.now())
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
image.png
image.png
image.png

再加一个额外的功能

import time


now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
fname="D:/pythonworkspace/TextSimilarity/log/"+now+"similarity.log"

把这个fname替换到log文件的文件名那里,可以生成一日期时间为名的log日志文件

上一篇 下一篇

猜你喜欢

热点阅读