import time def write_log(content): with open('text.log','a+',encoding='utf-8') as fw: data = time.strftime('%Y-%m-%d %H:%M:%S') s = '%s,内容 %s'%(data,content) print(s) fw.write(s)
调用log模块
import nnlog import time log = nnlog.Logger('test.log',level='info',backCount=1,when='D')#设置默认级别,保留最新的1天log,1天生产1份log log.debug('调试信息') log.info('正常打印信息') log.warning('警告') log.error('错误信息')