1 #ifndef __LOGFACILITY_H__
2 #define __LOGFACILITY_H__
8 #include <bias_config.h>
9 #include <Base/Common/FileHandling.hh>
10 #include <Base/Debug/TimeMeasure.hh>
60 # pragma warning (disable: 4127)
64 #define BIASLOG(x,y){\
65 std::ostream _cods_(std::cout.rdbuf()); \
66 BIAS::LogFacility::Instance()->GetLogStream(_cods_); \
67 if(x<=BIAS::LogFacility::Instance()->GetLogLevel() && _cods_.good()) { \
68 if(BIAS::LogFacility::Instance()->GetShowCodeInfo()){ \
69 std::string file = BIAS::FileHandling::Filename(__FILE__);\
70 std::string time = BIAS::TimeMeasure::GetCurrentTimeAsString();\
71 std::string date = BIAS::TimeMeasure::GetDateAsString();\
72 _cods_<<date<<", "<<time<<": "<<file<<", "<< __LINE__ << " : ";\
74 _cods_<<y<<std::endl<<std::flush; \
76 if( BIAS::LogFacility::Instance()->GetAbortOnFatal() && x==BIAS::BIAS_LOG_FATAL){ \
77 _cods_<<"Aborting in "<<__FILE__<<", "<<__LINE__<<std::endl<<std::flush;\
82 #define BIASLOGALWAYS(y){\
83 std::ostream _cods_(std::cout.rdbuf()); \
84 this->GetLogStream(_cods_); \
85 if(x<=this->dLogLevel_ && _cods_.good()) { \
86 _cods_<<y<<std::endl; _cods_.flush();\
96 #ifndef PLAIN_COUT_LOGGING
97 # define BLD(y) BIASLOG(BIAS::BIAS_LOG_DEBUG, y)
98 # define BLI(y) BIASLOG(BIAS::BIAS_LOG_INFO, y)
99 # define BLW(y) BIASLOG(BIAS::BIAS_LOG_WARNING, y)
100 # define BLF(y) BIASLOG(BIAS::BIAS_LOG_FATAL, y)
102 # define BLD(y) cout<< y<<endl;
103 # define BLI(y) cout<< y<<endl;
104 # define BLW(y) cout<< y<<endl;
105 # define BLF(y) cout<< y<<endl;
125 if (pInstance_== NULL)
133 static void DeleteInstance();
136 if(zLogFileStream_.is_open())
137 zLogFileStream_.close();
141 zLogFileStream_.open(sFileName.c_str(), std::ios_base::out | std::ios_base::trunc);
143 zLogStream_.rdbuf(zLogFileStream_.rdbuf());
148 dLogLevel_ = dLogLevel;
157 if (zLogFileStream_.is_open())
158 zLogFileStream_.close();
159 zLogStream_.rdbuf(zStream.rdbuf());
164 zStream.rdbuf(zLogStream_.rdbuf());
174 if(zLogFileStream_.is_open())
175 zLogFileStream_.close();
176 zLogStream_.rdbuf(std::cerr.rdbuf());
181 zLogStream_<<
"current log level is ";
184 case BIAS_LOG_NONE: zLogStream_<<
"BIAS_LOG_NONE"<<std::endl;
break;
185 case BIAS_LOG_FATAL: zLogStream_<<
"BIAS_LOG_FATAL"<<std::endl;
break;
187 case BIAS_LOG_INFO: zLogStream_<<
"BIAS_LOG_INFO"<<std::endl;
break;
188 case BIAS_LOG_DEBUG: zLogStream_<<
"BIAS_LOG_DEBUG"<<std::endl;
break;
203 return bAbortOnFatal_;
216 if (zLogFileStream_.is_open()) {
217 zLogFileStream_.close();
218 zLogStream_.rdbuf(std::cerr.rdbuf());
224 std::ostream zLogStream_;
bool OpenLogFile(const std::string &sFileName)
void SetShowCodeInfo(bool b)
bool SetLogStream(std::ostream zStream)
static LogFacility * Instance()
bool SetLogLevel(BIAS_LOG_LEVEL dLogLevel)
static LogFacility * pInstance_
void SetAbortOnFatal(bool b)
BIAS_LOG_LEVEL dLogLevel_
std::ostream & GetLogStream()
BIAS_LOG_LEVEL GetLogLevel()
bool GetLogStream(std::ostream &zStream)
std::ofstream zLogFileStream_