def write_exception(message=None): """ Function to be called after catching an exception. Writes exception details to log file and console :input: message - additional debug message to be written to log (containing vaiable values, or other useful debugging info) :return: None """ etype, value, tb = exc_info() logger.error("{}: {}.\n Check log file for details".format(etype, value)) logger.debug(''.join(format_exception(etype, value, tb))) if message: logger.debug(message) if not Globals.PROBLEMS: Globals.PROBLEMS = 1
file_parser.write_questions(make_output_path(Globals.OPUT_Q)) # SurveysQuestions.tab file_parser.write_surveysquestions(make_output_path(Globals.OPUT_SQ)) # Respondents.tab file_parser.write_respondents(make_output_path(Globals.OPUT_R)) # QuestionResponses.tab file_parser.write_responses(make_output_path(Globals.OPUT_QR)) # write ro MySQL if args.write_to_db: file_parser.write_all_to_mysql(Globals.SERVER_NAME, Globals.USER, Globals.PASS, Globals.DB_NAME) else: logger.info("Writing only to database.") file_parser.write_all_to_mysql(Globals.SERVER_NAME, Globals.USER, Globals.PASS, Globals.DB_NAME) if __name__ == "__main__": log_delimiter = "#"*20 + strftime("%a, %d %b %Y %X +0000", gmtime()) + "#"*10 logger.debug("\n"*2 + log_delimiter + "\n") main() if Globals.PROBLEMS: print "" logger.error("\tProblems detected. Check messages above and log file for details.") print "\nDebug log: '{}'\n".format(os.path.join(Globals.LOG_FILE_PATH, Globals.LOG_FILE))