Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 3d4e96ddbc9836d6e3ad5e19cef9e9bb08e2167b Mon Sep 17 00:00:00 2001
- From: Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>
- Date: Sat, 13 Nov 2010 13:30:50 +0100
- Subject: [PATCH] Finally fix the logPerDay log option.
- The static std::string date variable had two nasty problems.
- Would it have been static or be named 'date',
- and it would have not worked right.
- I also made the logger add the proper date on the archived log
- when changing the current day.
- Resolved: TMW-Mantis #530.
- ---
- src/utils/logger.cpp | 23 +++++++++++++++++------
- 1 files changed, 17 insertions(+), 6 deletions(-)
- diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp
- index 2053c9a..d24735b 100644
- --- a/src/utils/logger.cpp
- +++ b/src/utils/logger.cpp
- @@ -52,6 +52,12 @@ long Logger::mMaxFileSize = 1024; // 1 Mb
- bool Logger::mSwitchLogEachDay = false;
- /** Last call date */
- static std::string mLastCallDate = "";
- +/**
- + * Old date
- + * For code simplificatiion, the old Date is kept separate
- + * from the last call date.
- + */
- +static std::string mOldDate = "";
- /**
- * Gets the current time.
- @@ -114,11 +120,14 @@ static std::string getCurrentDate()
- */
- bool getDayChanged()
- {
- - static std::string date = getCurrentDate();
- - if (mLastCallDate != date)
- + std::string dayDate = getCurrentDate();
- +
- + if (mLastCallDate != dayDate)
- {
- + // Keep track of the old date.
- + mOldDate = mLastCallDate;
- // Reset the current date for next call.
- - mLastCallDate = date;
- + mLastCallDate = dayDate;
- return true;
- }
- return false;
- @@ -153,7 +162,7 @@ void Logger::setLogFile(const std::string &logFile, bool append)
- append ? std::ios::app : std::ios::trunc);
- mFilename = logFile;
- - mLastCallDate = getCurrentDate();
- + mLastCallDate = mOldDate = getCurrentDate();
- if (!mLogFile.is_open())
- {
- @@ -212,8 +221,10 @@ void Logger::switchLogs()
- // Update current filesize
- long fileSize = mLogFile.tellp();
- + bool dayJustChanged = getDayChanged();
- +
- if ((fileSize >= (mMaxFileSize * 1024))
- - || (mSwitchLogEachDay && getDayChanged()))
- + || (mSwitchLogEachDay && dayJustChanged))
- {
- // Close logfile, rename it and open a new one
- mLogFile.flush();
- @@ -222,7 +233,7 @@ void Logger::switchLogs()
- // Stringify the time, the format is: path/yyyy-mm-dd-n_logFilename.
- using namespace std;
- ostringstream os;
- - os << getCurrentDate();
- + os << (dayJustChanged ? mOldDate : getCurrentDate());
- int fileNum = 1;
- ResourceManager::splittedPath filePath =
- --
- 1.7.2.3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement