iSpike
2.1
Spike conversion library for robotics
|
00001 //iSpike includes 00002 #include <iSpike/Log/Log.hpp> 00003 using namespace ispike; 00004 00005 //Other includes 00006 #include <boost/date_time.hpp> 00007 #include <stdio.h> 00008 00009 int Log::currentId = 0; 00010 00012 Log::Log(){ 00013 os.precision(4); 00014 } 00015 00017 Log::~Log(){ 00018 os << endl; 00019 fprintf(stderr, "%s", os.str().c_str()); 00020 fflush(stderr); 00021 } 00022 00023 00024 TLogLevel& Log::ReportingLevel(){ 00025 static TLogLevel reportingLevel(LOG_DEBUG); 00026 return reportingLevel; 00027 } 00028 00029 00030 string Log::logLevelToString(TLogLevel level){ 00031 string result; 00032 switch(level){ 00033 case LOG_EMERGENCY: 00034 result = "Emergency"; 00035 break; 00036 case LOG_ALERT: 00037 result = "Alert"; 00038 break; 00039 case LOG_CRITICAL: 00040 result = "Critical"; 00041 break; 00042 case LOG_ERROR: 00043 result = "Error"; 00044 break; 00045 case LOG_WARNING: 00046 result = "Warning"; 00047 break; 00048 case LOG_NOTICE: 00049 result = "Notice"; 00050 break; 00051 case LOG_INFO: 00052 result = "Info"; 00053 break; 00054 case LOG_DEBUG: 00055 result = "Debug"; 00056 break; 00057 } 00058 return result; 00059 } 00060 00061 ostringstream& Log::Get(TLogLevel level){ 00062 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); 00063 os << now; 00064 os << " " << this->logLevelToString(level) << ": " << currentId << ": "; 00065 int size = 9 - this->logLevelToString(level).size(); 00066 os << string(size, ' '); 00067 currentId++; 00068 return os; 00069 } 00070