#include "Logger.hpp" #include #include namespace Plains { namespace Core { using std::cout; using std::cerr; using std::endl; //static string getTimeStamp() { return ctime ( time ( 0 ) ); } Logger::Logger(enum Level logLevel, EventBus& eventBus) : logLevel(logLevel), eventBus(eventBus) { logFile = ofstream("plains.log"); if (!logFile) { cerr << "Unable to open Logfile" << endl; //logFile = cout.fstream; } else { cout << "Log file opened" << endl; //oldStdOut = cout.rdbuf(); //cout.rdbuf(logFile.rdbuf()); } } Logger::~Logger() { logFile.close(); } void Logger::setLogLevel(Level level) { } void Logger::log(Level lvl, const string& msg) { log ( lvl, msg.c_str() ); } void Logger::log(Level lvl, const char* msg) { switch ( lvl ) { case DEBUG: debug (msg); break; case INFO: info (msg); break; case WARN: warn (msg); break; case FATAL: fatal (msg); break; } } void Logger::debug ( const string& msg ) { logFile << "DATESTAMP [DEBUG] " << msg << endl; } void Logger::debug ( const char* msg ) { logFile << "DATESTAMP [DEBUG] " << msg << endl; } void Logger::info ( const string& msg ) { if ( logLevel >= INFO ) logFile << "DATESTAMP [INFO] " << msg << endl; } void Logger::info ( const char* msg ) { if ( logLevel >= INFO ) logFile << "DATESTAMP [INFO] " << msg << endl; } void Logger::warn ( const string& msg ) { if ( logLevel >= WARN ) logFile << "DATESTAMP [WARN] " << msg << endl; } void Logger::warn ( const char* msg ) { if ( logLevel >= WARN ) logFile << "DATESTAMP [WARN] " << msg << endl; } void Logger::fatal ( const string& msg ) { if ( logLevel == FATAL ) logFile << "DATESTAMP [FATAL] " << msg << endl; } void Logger::fatal ( const char* msg ) { if ( logLevel == FATAL ) logFile << "DATESTAMP [FATAL] " << msg << endl; } }}