码迷,mamicode.com
首页 > 其他好文 > 详细

输出错误日志到文件

时间:2016-01-13 17:21:55      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

 

#!/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‘

 

输出错误日志到文件

标签:

原文地址:http://www.cnblogs.com/dreamer-fish/p/5127675.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!