Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. From 3d4e96ddbc9836d6e3ad5e19cef9e9bb08e2167b Mon Sep 17 00:00:00 2001
  2. From: Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>
  3. Date: Sat, 13 Nov 2010 13:30:50 +0100
  4. Subject: [PATCH] Finally fix the logPerDay log option.
  5.  
  6. The static std::string date variable had two nasty problems.
  7. Would it have been static or be named 'date',
  8. and it would have not worked right.
  9.  
  10. I also made the logger add the proper date on the archived log
  11. when changing the current day.
  12.  
  13. Resolved: TMW-Mantis #530.
  14. ---
  15. src/utils/logger.cpp | 23 +++++++++++++++++------
  16. 1 files changed, 17 insertions(+), 6 deletions(-)
  17.  
  18. diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp
  19. index 2053c9a..d24735b 100644
  20. --- a/src/utils/logger.cpp
  21. +++ b/src/utils/logger.cpp
  22. @@ -52,6 +52,12 @@ long Logger::mMaxFileSize = 1024; // 1 Mb
  23. bool Logger::mSwitchLogEachDay = false;
  24. /** Last call date */
  25. static std::string mLastCallDate = "";
  26. +/**
  27. + * Old date
  28. + * For code simplificatiion, the old Date is kept separate
  29. + * from the last call date.
  30. + */
  31. +static std::string mOldDate = "";
  32.  
  33. /**
  34. * Gets the current time.
  35. @@ -114,11 +120,14 @@ static std::string getCurrentDate()
  36. */
  37. bool getDayChanged()
  38. {
  39. - static std::string date = getCurrentDate();
  40. - if (mLastCallDate != date)
  41. + std::string dayDate = getCurrentDate();
  42. +
  43. + if (mLastCallDate != dayDate)
  44. {
  45. + // Keep track of the old date.
  46. + mOldDate = mLastCallDate;
  47. // Reset the current date for next call.
  48. - mLastCallDate = date;
  49. + mLastCallDate = dayDate;
  50. return true;
  51. }
  52. return false;
  53. @@ -153,7 +162,7 @@ void Logger::setLogFile(const std::string &logFile, bool append)
  54. append ? std::ios::app : std::ios::trunc);
  55.  
  56. mFilename = logFile;
  57. - mLastCallDate = getCurrentDate();
  58. + mLastCallDate = mOldDate = getCurrentDate();
  59.  
  60. if (!mLogFile.is_open())
  61. {
  62. @@ -212,8 +221,10 @@ void Logger::switchLogs()
  63. // Update current filesize
  64. long fileSize = mLogFile.tellp();
  65.  
  66. + bool dayJustChanged = getDayChanged();
  67. +
  68. if ((fileSize >= (mMaxFileSize * 1024))
  69. - || (mSwitchLogEachDay && getDayChanged()))
  70. + || (mSwitchLogEachDay && dayJustChanged))
  71. {
  72. // Close logfile, rename it and open a new one
  73. mLogFile.flush();
  74. @@ -222,7 +233,7 @@ void Logger::switchLogs()
  75. // Stringify the time, the format is: path/yyyy-mm-dd-n_logFilename.
  76. using namespace std;
  77. ostringstream os;
  78. - os << getCurrentDate();
  79. + os << (dayJustChanged ? mOldDate : getCurrentDate());
  80.  
  81. int fileNum = 1;
  82. ResourceManager::splittedPath filePath =
  83. --
  84. 1.7.2.3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement