i wants write exception details in file: tried below"
def writeerrorlog(e) : global lcnt lsterr=[] iurlfoutputfile = open("c:\error.log", "a") csvurlfinfowriter = csv.writer(iurlfoutputfile, delimiter=',', lineterminator='\n') exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] csvurlfinfowriter.writerow('[exc_type, filename, script_line no,inputfile_lineno]') lsterr.append(exc_type) lsterr.append(fname) lsterr.append(g_lcnt) value in lsterr : csvurlfinfowriter.writerow(value) iurlfoutputfile.close()
in except block:
except exception e : writeerrorlog(e)
its not working, can correct me? or can suggest better option? thanks!!
i use python loggin -> http://docs.python.org/2/library/logging.html can format lines ',' delimited, example
[formatter_generic_form] format='%(asctime)s , %(levelname)s , %(message)s' datefmt='%y-%m-%d %h:%m:%s'
datetime, level_of_log, whatever_message_you_want_to_log
i recommend http://docs.python.org/2/howto/logging.html#logging-basic-tutorial start
Comments
Post a Comment