BambooIsland: C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/Logger.cpp Source File

BambooIsland Abgabe 2

- Main Page
- Related Pages
- Classes
- Files

- File List

# C:/Users/easterbunny/Desktop/Echtzeitgraphik-LU/trunk/src/Logger.cpp

    00001 /*
    00002  * source file for Logger class
    00003  * written by: christian moellinger <ch.moellinger@gmail.com>
    00004  * 10/2010
    00005  */
    00006
    00007 #include <iostream>
    00008 #include <fstream>
    00009 #include <stdexcept>
    00010 #include "Logger.h"
    00011
    00012 using namespace std;
    00013
    00014 Logger *Logger::instance()
    00015 {
    00016     static Logger singelton_instance;
    00017     return &singelton_instance;
    00018 }
    00019
    00020 Logger::Logger()
    00021 {
    00022     this->logfile.open("log.txt", ios::out);
    00023 }
    00024
    00025 Logger::~Logger()
    00026 {
    00027     this->logfile.close();
    00028 }
    00029
    00030 void Logger::setLogLevelForConsole(LogLevel loglevel)
    00031 {
    00032     this->loglevel_console = loglevel;
    00033 }
    00034
    00035 void Logger::setLogLevelForFile(LogLevel loglevel)
    00036 {
    00037     this->loglevel_file = loglevel;
    00038 }
    00039
    00040 void Logger::log(LogLevel level, const char *message)
    00041 {
    00042     if (level >= this->loglevel_console)
    00043     {
    00044         cerr << this->getLevelName(level) << " " << message << endl;
    00045     }
    00046
    00047     if (level >= this->loglevel_file)
    00048     {
    00049         this->logfile << this->getLevelName(level) << " " << message << endl;
    00050     }
    00051
    00052     if (level >= FATAL)
    00053         throw new std::runtime_error(message);
    00054 }
    00055
    00056 void Logger::log(LogLevel level, const std::string message)
    00057 {
    00058     this->log(level, message.data());
    00059 }
    00060
    00061 const char *Logger::getLevelName(LogLevel level)
    00062 {
    00063     switch (level)
    00064     {
    00065     case TRACE:
    00066         return "TRACE";
    00067         break;
    00068     case DEBUG:
    00069         return "DEBUG";
    00070         break;
    00071     case WARN:
    00072         return "WARNING";
    00073         break;
    00074     case ERROR:
    00075         return "ERROR";
    00076         break;
    00077     case FATAL:
    00078         return "FATAL";
    00079         break;
    00080     default:
    00081         throw new std::invalid_argument("wrong loglevel used!");
    00082     }
    00083 }

All Classes Functions Variables Enumerations Enumerator