- Main Page
- Modules
- Classes
- Files
- Related Pages

- File List
- File Members

# src/Logger.h

Go to the documentation of this file.

    00001 #ifndef LOGGER_H_
    00002 #define LOGGER_H_
    00003
    00004 #include <fstream>
    00005 #include <sstream>
    00006 #include <map>
    00007 #include <string>
    00008
    00009 #include "config.h"
    00010
    00011 //DEBUG < INFO < WARN < ERROR < FATAL < NONE
    00012 #define LOG_DEBUG   0
    00013 #define LOG_INFO    1
    00014 #define LOG_WARN    2
    00015 #define LOG_ERROR   3
    00016 #define LOG_FATAL   4
    00017 #define LOG_NONE    5
    00018
    00019 #define _DEBUG(msg) {\
    00020     if (Logger::getLevel() == LOG_DEBUG) Logger::_oss << "DEBUG " << __PRETTY_FUNCTION__ << ":" << __LINE__ << " ";\
    00021     Logger::_oss << msg;\
    00022     Logger::getInstance()->log(LOG_DEBUG);\
    00023 };
    00024
    00025 #define _INFO(msg)  {\
    00026     if (Logger::getLevel() == LOG_DEBUG) Logger::_oss << "INFO " << __PRETTY_FUNCTION__ << ":" << __LINE__ << " ";\
    00027     Logger::_oss << msg;\
    00028     Logger::getInstance()->log(LOG_INFO);\
    00029 };
    00030
    00031 #define _WARN(msg)  {\
    00032     if (Logger::getLevel() == LOG_DEBUG) Logger::_oss << "WARNING " << __PRETTY_FUNCTION__ << ":" << __LINE__ << " ";\
    00033     Logger::_oss << msg;\
    00034     Logger::getInstance()->log(LOG_WARN);\
    00035 };
    00036
    00037 #define _ERROR(msg) {\
    00038     if (Logger::getLevel() == LOG_DEBUG) Logger::_oss << "ERROR " << __PRETTY_FUNCTION__ << ":" << __LINE__ << " ";\
    00039     Logger::_oss << msg;\
    00040     Logger::getInstance()->log(LOG_ERROR);\
    00041 };
    00042
    00043 #define _FATAL(msg) {\
    00044     if (Logger::getLevel() == LOG_DEBUG) Logger::_oss << "FATAL ERROR " << __PRETTY_FUNCTION__ << ":" << __LINE__ << " ";\
    00045     Logger::_oss << msg;\
    00046     Logger::getInstance()->log(LOG_FATAL);\
    00047 };
    00048
    00049 class Logger
    00050 {
    00051 public:
    00052     virtual ~Logger();
    00053
    00055     static Logger* getInstance();
    00057     static void setFilename(std::string filename) { _filename = filename; };
    00059     static void setLevel(int level) { if (level >= LOG_DEBUG && level <= LOG_FATAL) _level = level; };
    00060     static int getLevel() { return _level; };
    00061
    00063     void log(int severity);
    00064
    00066     static std::ostringstream _oss;
    00067
    00068 private:
    00070     static Logger* _instance;
    00072     static std::string _filename;
    00074     static int _level;
    00076     std::ofstream _file;
    00077
    00078     Logger();
    00079     Logger(const Logger&);
    00080     Logger& operator=(const Logger&);
    00081 };
    00082
    00083 #endif /*LOGGER_H_*/