diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-04-01 00:14:51 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-04-01 00:14:51 +0000 |
commit | 05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c (patch) | |
tree | 921b18da0dc52e7562f0c6a02e5343f9b582cf64 /src/log.cpp | |
parent | 78c72d1463735ad6e3a176f89d3c41a5ed71fc40 (diff) | |
download | mana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.tar.gz mana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.tar.bz2 mana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.tar.xz mana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.zip |
* The client will now only attempt to load .tmx or .tmx.gz files.
* When unable to connect to char server, report IP to which it can't connect.
* Cleaned up logger a bit.
Diffstat (limited to 'src/log.cpp')
-rw-r--r-- | src/log.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/log.cpp b/src/log.cpp index e1db8d4f..df92e49e 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -24,27 +24,30 @@ #include <windows.h> #endif -FILE* logfile; +#include <sstream> -Logger::Logger(std::string logFilename) +Logger::Logger(const std::string &logFilename) { logFile.open(logFilename.c_str(), std::ios_base::trunc); - if ( !logFile.is_open() ) + + if (!logFile.is_open()) { - std::cout << "Warning: error while opening log file." << std::endl; + std::cout << "Warning: error while opening log file.\n"; } - } Logger::~Logger() { - logFile.close(); + if (logFile.is_open()) + { + logFile.close(); + } } void Logger::log(const char *log_text, ...) { - if ( logFile.is_open() ) + if (logFile.is_open()) { char* buf = new char[1024]; va_list ap; @@ -59,18 +62,19 @@ void Logger::log(const char *log_text, ...) time(&t); // Print the log entry - logFile << "["; - logFile << ((((t / 60) / 60) % 24 < 10) ? "0" : ""); - logFile << (int)(((t / 60) / 60) % 24); - logFile << ":"; - logFile << (((t / 60) % 60 < 10) ? "0" : ""); - logFile << (int)((t / 60) % 60); - logFile << ":"; - logFile << ((t % 60 < 10) ? "0" : ""); - logFile << (int)(t % 60); - logFile << "] "; + std::stringstream timeStr; + timeStr << "["; + timeStr << ((((t / 60) / 60) % 24 < 10) ? "0" : ""); + timeStr << (int)(((t / 60) / 60) % 24); + timeStr << ":"; + timeStr << (((t / 60) % 60 < 10) ? "0" : ""); + timeStr << (int)((t / 60) % 60); + timeStr << ":"; + timeStr << ((t % 60 < 10) ? "0" : ""); + timeStr << (int)(t % 60); + timeStr << "] "; - logFile << buf << std::endl; + logFile << timeStr.str() << buf << std::endl; // Delete temporary buffer delete[] buf; @@ -83,9 +87,8 @@ void Logger::error(const std::string &error_text) #ifdef WIN32 MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); #else - log("Error :"); - log(error_text.c_str()); + std::cerr << "Error: " << error_text << std::endl; + log("Error: %s", error_text.c_str()); #endif exit(1); } - |