diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-10-14 21:19:07 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-10-14 21:19:07 +0200 |
commit | 1d9374215d8e6ad1160596dcd52fca201aeb2195 (patch) | |
tree | 6f4a5e280e9953ec6de8909a93e90d4d83f9fe3c /src/utils | |
parent | dd703d614620846176e832eda0f37b5e20704c81 (diff) | |
download | manaserv-1d9374215d8e6ad1160596dcd52fca201aeb2195.tar.gz manaserv-1d9374215d8e6ad1160596dcd52fca201aeb2195.tar.xz manaserv-1d9374215d8e6ad1160596dcd52fca201aeb2195.zip |
Hopefully fix the logging rotation this time.
Added an extension to the ResMan::exist() function
in order to get file existence even not in search path.
Reviewed-by: CodyMartin.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/logger.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp index 45a68eb..6ad008c 100644 --- a/src/utils/logger.cpp +++ b/src/utils/logger.cpp @@ -70,12 +70,12 @@ static std::string getCurrentTime() // constituents. local = *(localtime(&now)); - // Stringify the time, the format is: [hh-mm-ss] + // Stringify the time, the format is: hh:mm:ss using namespace std; ostringstream os; os << setw(2) << setfill('0') << local.tm_hour - << "-" << setw(2) << setfill('0') << local.tm_min - << "-" << setw(2) << setfill('0') << local.tm_sec; + << ":" << setw(2) << setfill('0') << local.tm_min + << ":" << setw(2) << setfill('0') << local.tm_sec; return os.str(); } @@ -112,10 +112,10 @@ static std::string getCurrentDate() * * @return whether the day has changed. */ -static bool getDayChanged() +bool getDayChanged() { static std::string date = getCurrentDate(); - if (mLastCallDate.compare(date)) + if (mLastCallDate != date) { // Reset the current date for next call. mLastCallDate = date; @@ -209,49 +209,49 @@ void Logger::switchLogs() return; // Update current filesize - long mFileSize = mLogFile.tellp(); + long fileSize = mLogFile.tellp(); - if ((mFileSize >= mMaxFileSize * 1024) + if ((fileSize >= (mMaxFileSize * 1024)) || (mSwitchLogEachDay && getDayChanged())) { // Close logfile, rename it and open a new one mLogFile.flush(); mLogFile.close(); - // Stringify the time, the format is: yyyy-mm-dd_hh-mm-ss-logFilename. + // Stringify the time, the format is: path/yyyy-mm-dd-n_logFilename. using namespace std; ostringstream os; os << getCurrentDate(); int fileNum = 1; - std::string newFileName = os.str() + "-" + toString<int>(fileNum) - + "_" + mFilename; + ResourceManager::splittedPath filePath = + ResourceManager::splitFileNameAndPath(mFilename); + + std::string newFileName; // Keeping a hard limit of 100 files per day. - while (ResourceManager::exists(newFileName) && fileNum < 100) + do { - fileNum++; - newFileName = os.str() + "-" + toString<int>(fileNum) - + "_" + mFilename; + newFileName = filePath.path + os.str() + + "-" + toString<int>(fileNum) + + "_" + filePath.file; } + while (ResourceManager::exists(newFileName, false) && ++fileNum < 100); - if (rename(mFilename.c_str(), newFileName.c_str())) + if (rename(mFilename.c_str(), newFileName.c_str()) != 0) { - ostringstream errorOs; - errorOs << "Error renaming file: " << mFilename << " to: " - << newFileName << std::endl << "Continuing on the same log file."; - perror(errorOs.str().c_str()); - // Continue appending on the original file. setLogFile(mFilename, true); + mLogFile << "Error renaming file: " << mFilename << " to: " + << newFileName << std::endl << "Keep logging on the same log file." + << std::endl; } else { // Keep the logging after emptying the original log file. setLogFile(mFilename); + mLogFile << "---- Continue logging from former file " << newFileName + << " ----" << std::endl; } - - mLogFile << "---- Continue logging from former file " << os.str() - << " ----" << std::endl; } } |