summaryrefslogtreecommitdiff
path: root/src/log.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2005-03-23 22:03:08 +0000
committerYohann Ferreira <bertram@cegetel.net>2005-03-23 22:03:08 +0000
commita3c07843e1852980edb9414f3fcb069e5a3e12ec (patch)
tree02a1fd099830a1055f90c8b22472cd2d6418eadd /src/log.cpp
parent255da423d061e6f0ee3db009a7ed2c1ec8e60315 (diff)
downloadmana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.tar.gz
mana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.tar.bz2
mana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.tar.xz
mana-a3c07843e1852980edb9414f3fcb069e5a3e12ec.zip
First working implementation of new logger (Step 2/3)
Diffstat (limited to 'src/log.cpp')
-rw-r--r--src/log.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/log.cpp b/src/log.cpp
index da6d8fb2..b73b2662 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -29,7 +29,7 @@ FILE* logfile;
Logger::Logger(std::string logFilename)
{
- logFile.open("tmw.log");
+ logFile.open(logFilename.c_str(), std::ios_base::trunc);
if ( !logFile.is_open() )
{
std::cout << "Warning: error while opening log file." << std::endl;
@@ -52,19 +52,19 @@ void Logger::log(std::string log_text)
time(&t);
// Print the log entry
- std::string dateString = "[";
- dateString += ((((t / 60) / 60) % 24 < 10) ? "0" : "");
- dateString += (((t / 60) / 60) % 24);
- dateString += ":";
- dateString += (((t / 60) % 60 < 10) ? "0" : "");
- dateString += ((t / 60) % 60);
- dateString += ":";
- dateString += ((t % 60 < 10) ? "0" : "");
- dateString += (t % 60);
- dateString += "] ";
+ 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 << "] ";
// Print the log entry
- logFile << dateString << log_text << std::endl;
+ logFile << log_text << std::endl;
}
}
@@ -85,19 +85,18 @@ void Logger::log(const char *log_text, ...)
time(&t);
// Print the log entry
- std::string dateString = "[";
- dateString += ((((t / 60) / 60) % 24 < 10) ? "0" : "");
- dateString += (((t / 60) / 60) % 24);
- dateString += ":";
- dateString += (((t / 60) % 60 < 10) ? "0" : "");
- dateString += ((t / 60) % 60);
- dateString += ":";
- dateString += ((t % 60 < 10) ? "0" : "");
- dateString += (t % 60);
- dateString += "] ";
- dateString += buf;
+ 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 << "] ";
- logFile << dateString << std::endl;
+ logFile << buf << std::endl;
// Delete temporary buffer
delete[] buf;