diff options
author | Chris Wilson <chris+github@qwirx.com> | 2009-03-29 14:08:12 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2009-03-29 14:08:12 +0000 |
commit | 077b00d6c5c967e1403a39fa5bd8843c039199eb (patch) | |
tree | 95942e8aaec11650451e00a2ee31582bd5ca32b4 /lib/common | |
parent | ef3d1642c083a9c69eb48c6ab8ecc9be43dfbcfc (diff) |
Add date to file logger, as requested by Kenny Millington.
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/BoxTime.cpp | 14 | ||||
-rw-r--r-- | lib/common/BoxTime.h | 3 | ||||
-rw-r--r-- | lib/common/Logging.cpp | 4 | ||||
-rw-r--r-- | lib/common/Timer.cpp | 2 |
4 files changed, 16 insertions, 7 deletions
diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp index 0d099db5..d05c0a6c 100644 --- a/lib/common/BoxTime.cpp +++ b/lib/common/BoxTime.cpp @@ -53,7 +53,7 @@ box_time_t GetCurrentBoxTime() return SecondsToBoxTime(time(0)); } -std::string FormatTime(box_time_t time, bool showMicros) +std::string FormatTime(box_time_t time, bool includeDate, bool showMicros) { std::ostringstream buf; @@ -68,8 +68,16 @@ std::string FormatTime(box_time_t time, bool showMicros) if (localtime_r(&seconds, &tm_now) != NULL) #endif { - buf << std::setfill('0') << - std::setw(2) << tm_ptr->tm_hour << ":" << + buf << std::setfill('0'); + + if (includeDate) + { + buf << std::setw(4) << (tm_ptr->tm_year + 1900) << "-" << + std::setw(2) << (tm_ptr->tm_mon + 1) << "-" << + std::setw(2) << (tm_ptr->tm_mday) << " "; + } + + buf << std::setw(2) << tm_ptr->tm_hour << ":" << std::setw(2) << tm_ptr->tm_min << ":" << std::setw(2) << tm_ptr->tm_sec; diff --git a/lib/common/BoxTime.h b/lib/common/BoxTime.h index 2023db36..6681bbbd 100644 --- a/lib/common/BoxTime.h +++ b/lib/common/BoxTime.h @@ -40,6 +40,7 @@ inline uint64_t BoxTimeToMicroSeconds(box_time_t Time) return Time; } -std::string FormatTime(box_time_t time, bool showMicros = false); +std::string FormatTime(box_time_t time, bool includeDate, + bool showMicros = false); #endif // BOXTIME__H diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index 9248bd35..1f872d93 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -288,7 +288,7 @@ bool Console::Log(Log::Level level, const std::string& rFile, if (sShowTime) { - buf << FormatTime(GetCurrentBoxTime(), sShowTimeMicros); + buf << FormatTime(GetCurrentBoxTime(), false, sShowTimeMicros); buf << " "; } @@ -449,7 +449,7 @@ bool FileLogger::Log(Log::Level Level, const std::string& rFile, Logging::Remove(this); std::ostringstream buf; - buf << FormatTime(GetCurrentBoxTime(), false); + buf << FormatTime(GetCurrentBoxTime(), true, false); buf << " "; if (Level <= Log::FATAL) diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp index 01afa91b..137ad45f 100644 --- a/lib/common/Timer.cpp +++ b/lib/common/Timer.cpp @@ -357,7 +357,7 @@ Timer::Timer(size_t timeoutSecs, const std::string& rName) else { BOX_TRACE(TIMER_ID "initialised for " << timeoutSecs << - " secs, to fire at " << FormatTime(mExpires, true)); + " secs, to fire at " << FormatTime(mExpires, false, true)); } #endif |