00001 #ifndef ZTT_DCS_LOGGER_HPP
00002 #define ZTT_DCS_LOGGER_HPP
00003
00004 #include <fstream>
00005 #include <stdexcept>
00006 #include "ace/Synch.h"
00007
00008 #include "FedMessenger.hpp"
00009
00010
00011 namespace ztt { namespace dcs {
00012
00016 #ifndef __BENCHMARK
00017 #define DEFAULT_LOCAL_LOGLEVEL (Msg_Info+Msg_Error+Msg_Warning+Msg_Alarm)
00018 #endif
00019
00020 #ifdef __BENCHMARK
00021 #define DEFAULT_LOCAL_LOGLEVEL (Msg_Info+Msg_Error+Msg_Warning+Msg_Alarm+Msg_Debug)
00022 #endif
00023
00026 #ifndef __BENCHMARK
00027 #define DEFAULT_REMOTE_LOGLEVEL (Msg_Info+Msg_Error+Msg_Warning+Msg_Alarm)
00028 #endif
00029 #ifdef __BENCHMARK
00030 #define DEFAULT_REMOTE_LOGLEVEL (Msg_Info+Msg_Error+Msg_Warning+Msg_Alarm+Msg_Debug)
00031 #endif
00032
00035 #define FILE_CLOSE_COUNT 3
00036
00040 #define INTERCOM_DATA_ACCESS "InterComLayer-DataAccess"
00041
00042
00043
00044
00056 class Logger {
00057 public:
00058
00073 static Logger* createLogger(FedMessenger* pMessenger);
00074
00080 virtual ~Logger();
00081
00090 static const Logger* getLogger();
00091
00100 void createLogMessage(unsigned int type, char* origin, char* description) const;
00101
00111 void relayLogEntry(MessageStruct* msgStruct) const;
00112
00130 void setLogLevel(unsigned int logLevel);
00131
00150 void setRemoteLogLevel(unsigned int remoteLogLevel);
00151
00158
00159
00160
00161
00167 unsigned int getLogLevel();
00168
00174 unsigned int getRemoteLogLevel();
00175
00176
00177
00178
00179 private:
00180
00189 Logger(FedMessenger* pMessenger);
00190
00195 static Logger* pInstance;
00196
00200 FedMessenger* mpMessenger;
00201
00205 std::ofstream* mLogFile;
00206
00210 char mFileName[40];
00211
00218 unsigned int mLogLevel;
00219
00228 unsigned int mRemoteLogLevel;
00229
00237 unsigned int mFileCount;
00238
00248 bool checkLogLevel(unsigned int event) const;
00249
00260 bool checkRemoteLogLevel(unsigned int event) const;
00261
00269 void sendLogEntry(MessageStruct* msgStruct) const;
00270
00281 bool writeLogEntry(MessageStruct* msgStruct);
00282
00286 ACE_Mutex mutex;
00292 int miLogDay;
00293 };
00294
00295
00296
00297 inline bool Logger::checkLogLevel(unsigned int event) const {
00298
00299 return (event & mLogLevel) ? true : false;
00300 }
00301
00302
00303 inline bool Logger::checkRemoteLogLevel(unsigned int event) const {
00304
00305 return (event & mRemoteLogLevel) ? true : false;
00306 }
00307
00308
00309 inline const Logger* Logger::getLogger() {
00310 if (pInstance == 0) {
00311 throw std::runtime_error("Logger has not been instanciated yet!");
00312 }
00313 return pInstance;
00314 }
00315
00316 } }
00317
00318 #endif