#!/usr/bin/python # -*- coding: utf-8 -*- #将错误日志输出到文件 import time log_path =‘/root/log.log‘ fo = open(log_path,‘a‘) a=0 try: result=10/a print result except StandardError, e: print ‘serror:‘, e fo.write(time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime())+‘\n‘+str(e)+‘\n‘) fo.close() else: print result+1 finally: print ‘The end‘
时间: 2024-11-05 02:23:00