00001 #include "ActionLogger.h" 00002 00003 #include "actasp/AspFluent.h" 00004 00005 00006 #include <ctime> 00007 00008 using namespace std; 00009 using namespace actasp; 00010 00011 ActionLogger::ActionLogger() : dest_file(NULL){} 00012 00013 00014 void ActionLogger::setFile(const std::string& path) { 00015 taskCompleted(); 00016 dest_file = new ofstream(path.c_str() , std::ofstream::app); 00017 time_t rawtime; 00018 struct tm * timeinfo; 00019 char time_string[10]; 00020 time (&rawtime); 00021 timeinfo = localtime (&rawtime); 00022 strftime (time_string,10,"%R",timeinfo); 00023 (*dest_file) << time_string << " "; 00024 00025 } 00026 00027 00028 void ActionLogger::actionStarted(const AspFluent& action) throw() { 00029 00030 if(dest_file) { 00031 (*dest_file) << action.toString() << " "; 00032 } 00033 } 00034 00035 void ActionLogger::actionTerminated(const AspFluent& action) throw() {} 00036 00037 ActionLogger::~ActionLogger() { 00038 taskCompleted(); 00039 } 00040 00041 void ActionLogger::taskCompleted() { 00042 if(dest_file) { 00043 (*dest_file) << endl; 00044 dest_file->close(); 00045 delete dest_file; 00046 dest_file = NULL; 00047 } 00048 } 00049