/***************************************************************************** - - - POLONY SEQUENCER ACQUISITION SUITE - - Church Lab - - Harvard Medical School - - - - Free software for running a Polony Sequencing automated microscope - - - - ========================================================================= - - - - - - reporter.cpp - - - - Class for logging information to screen and files - - - - Written by Greg Porreca, 02-15-2006 - - - - Revised - - - - - - This software may be used, modified, and distributed freely, but this - - header may not be modified and must appear at the top of this file. - - - - - *****************************************************************************/ #include "Reporter.h" Reporter::Reporter(){;} Reporter::Reporter(int debug){ DEBUG_LEVEL = debug; } Reporter::~Reporter(){ fclose(log_file); } void Reporter::set_debuglevel(int debug){ DEBUG_LEVEL = debug; } void Reporter::open(char filename[], char mode){ if(mode == 'r'){ if((log_file = fopen(filename, "r")) == NULL){ fprintf(stderr, "ERROR opening log output file %s, mode=%s.\n", filename, mode); exit(42); } } else if(mode == 'w'){ if((log_file = fopen(filename, "w")) == NULL){ fprintf(stderr, "ERROR opening log output file %s, mode=%s.\n", filename, mode); exit(42); } } else if(mode == 'a'){ if((log_file = fopen(filename, "a")) == NULL){ fprintf(stderr, "ERROR opening log output file %s, mode=%s.\n", filename, mode); exit(42); } } sprintf(log_string, "Using %s for log file", filename); this->log(log_string, 1); } void Reporter::error(char message[], int exit_flag){ fprintf(stderr, "ERROR: %s.\n", message); fprintf(log_file, "ERROR: %s.\n", message); fflush(log_file); if(exit_flag){ fprintf(stderr, "->EXITING.\n"); fprintf(log_file, "->EXITING.\n"); fflush(NULL); exit(42); } } void Reporter::log(char message[], int report_level){ fprintf(log_file, "%d %s\n", report_level, message); fflush(log_file); if(report_level <= DEBUG_LEVEL){ fprintf(stdout, "%d %s\n", report_level, message); } }