From 3dc60689b9327190eeecd42f6920299ef3e7b52c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 18 Nov 2012 22:20:56 +0000 Subject: Corrected dedicated server log timestamp issues. --- src/dedicated/console.cc | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'src/dedicated') diff --git a/src/dedicated/console.cc b/src/dedicated/console.cc index 5d16848..7986f2e 100644 --- a/src/dedicated/console.cc +++ b/src/dedicated/console.cc @@ -122,12 +122,21 @@ void Console::open_log() console_logfilename.clear(); con_warn << "Could not open logfile " << errfilename << std::endl; } else { - logfile.close(); - // dump console content for (Queue::iterator it = log().begin(); it != log().end(); it++) { - print((*it)); + int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, milliseconds = 0; + sys::get_localtime(year, month, day, hour, min, sec, milliseconds); + + logfile << std::setw(4) << std::setfill('0') << year << "-" + << std::setw(2) << std::setfill('0') << month << "-" + << std::setw(2) << std::setfill('0') << day << " " + << std::setw(2) << std::setfill('0') << hour << ":" + << std::setw(2) << std::setfill('0') << min << ":" + << std::setw(2) << std::setfill('0') << sec << " " + << std::setw(2) << " " + << aux::text_strip((*it)) << std::endl; } + logfile.close(); } } @@ -148,16 +157,18 @@ void Console::print(const std::string & text) std::ofstream logfile; logfile.open(console_logfilename.c_str(), std::ios::app); if (logfile.is_open()) { - int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, milliseconds = 0; - sys::get_localtime(year, month, day, hour, min, sec, milliseconds); - logfile << std::setw(4) << std::setfill('0') << year << "-" - << std::setw(2) << std::setfill('0') << month << "-" - << std::setw(2) << std::setfill('0') << day << " " - << std::setw(2) << std::setfill('0') << hour << ":" - << std::setw(2) << std::setfill('0') << min << ":" - << std::setw(2) << std::setfill('0') << sec << " " - << std::setw(2) << " " - << aux::text_strip(text) << std::endl; + if (!sys::console_timestamps()) { + int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, milliseconds = 0; + sys::get_localtime(year, month, day, hour, min, sec, milliseconds); + logfile << std::setw(4) << std::setfill('0') << year << "-" + << std::setw(2) << std::setfill('0') << month << "-" + << std::setw(2) << std::setfill('0') << day << " " + << std::setw(2) << std::setfill('0') << hour << ":" + << std::setw(2) << std::setfill('0') << min << ":" + << std::setw(2) << std::setfill('0') << sec << " " + << std::setw(2) << " "; + } + logfile << aux::text_strip(text) << std::endl; logfile.close(); } } @@ -260,9 +271,9 @@ void Console::draw_status() status << std::setw(4) << std::setfill('0') << year << "-" << std::setw(2) << std::setfill('0') << month << "-" << std::setw(2) << std::setfill('0') << day << " " - << std::setw(2) << hour << ":" - << std::setw(2) << min << ":" - << std::setw(2) << sec << " " + << std::setw(2) << std::setfill(' ') << hour << ":" + << std::setw(2) << std::setfill('0') << min << ":" + << std::setw(2) << std::setfill('0') << sec << " " << std::setw(2) << " "; // uptime @@ -283,7 +294,7 @@ void Console::draw_status() if (uptime_days > 0) { status << uptime_days << " " << aux::plural("day", uptime_days) << " "; } - status << std::setfill('0') << std::setw(2) << uptime_hours << ":" + status << std::setfill(' ') << std::setw(2) << uptime_hours << ":" << std::setfill('0') << std::setw(2) << uptime_minutes << ":" << std::setfill('0') << std::setw(2) << uptime_seconds; -- cgit v1.2.3