From 9301d3359df533f198b93150bc95473bfaa002ed Mon Sep 17 00:00:00 2001 From: Majid Date: Sun, 13 Jan 2013 13:22:14 +1100 Subject: [PATCH] closes #11 - Now you can clean logs every time you run application --- README.md | 8 ++++++++ easylogging++.h | 21 +++++++++++++-------- index.php | 2 +- samples/bin/many_logs.cpp.bin | Bin 30741 -> 30741 bytes samples/bin/time_tracker.cpp.bin | Bin 31037 -> 31037 bytes samples/bin/time_waster.cpp.bin | Bin 31051 -> 31051 bytes 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 23d228b33..02bef416a 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,14 @@ This will disable debug logs and status updates in main-exec binary. *Note*, when the logging is turned off, it will not affect any code, it will not result in any compilation error, in fact, compiler will ignore those lines. Even the functions defined using `SUB` and `FUNC` will behave normally as they would do otherwise when EasyLogging++ is not being used at all. +#### Cleaning Logs On Each Run +If you wish to clean log each time you run your C++ application, you can do this by defining macro `_ALWAYS_CLEAN_LOGS`. This is useful when you are doing regression testing on your application and always want to start with clean logs. See issue#11 for further details on initial request. + +As an example, you may compile your application as following if you wish to clean logs every time you execute application; +``` +g++ main.cpp -o main-exec -D _ALWAYS_CLEAN_LOGS +``` + #### Log Location By Log Level Since v2.0+, EasyLogging++ has configuration for custom log locations, that means; for example you can choose to log `DEBUG`s to log file but not to standard output (e.g, terminal) while `INFO` to both standard output and log file. This can be set by following configurations diff --git a/easylogging++.h b/easylogging++.h index 5c7ee2135..753c60740 100644 --- a/easylogging++.h +++ b/easylogging++.h @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////// // // // easylogging++.h - Core of EasyLogging++ // -// EasyLogging++ v3.17 // +// EasyLogging++ v3.18 // // Cross platform logging made easy for C++ applications // // Author Majid Khan // // http://www.icplusplus.com // @@ -219,11 +219,11 @@ static void createLogPath(void) { #if _WINDOWS || _LINUX || _MAC if ((::easyloggingpp::USE_CUSTOM_LOCATION) && (::easyloggingpp::CUSTOM_LOG_FILE_LOCATION.size() > 0) && (!::easyloggingpp::logPathExist())) { int status = -1; -#if _WINDOWS + #if _WINDOWS std::string pathDelimiter = "\\"; -#elif _LINUX || _MAC + #elif _LINUX || _MAC std::string pathDelimiter = "/"; -#endif //_WINDOWS + #endif //_WINDOWS std::string tempPath = CUSTOM_LOG_FILE_LOCATION; std::string dir = ""; short foundAt = -1; @@ -232,11 +232,11 @@ static void createLogPath(void) { dir = tempPath.substr(0, foundAt); if (dir != "") { madeSoFar += dir + pathDelimiter; -#if _WINDOWS + #if _WINDOWS status = _mkdir(madeSoFar.c_str()); -#elif _LINUX || _MAC + #elif _LINUX || _MAC status = mkdir(madeSoFar.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IWGRP | S_IRGRP | S_IXGRP | S_IWOTH | S_IXOTH); /* rwx,rwx,wx */ -#endif //_WINDOWS + #endif //_WINDOWS } tempPath = tempPath.erase(0, foundAt + 1); } @@ -333,7 +333,12 @@ static void init(void) { ::easyloggingpp::createLogPath(); // Log file if (::easyloggingpp::SAVE_TO_FILE) { - ::easyloggingpp::logFile = new std::ofstream(::easyloggingpp::kFinalFilename.c_str(), std::ofstream::out | std::ofstream::app); +#if defined(_ALWAYS_CLEAN_LOGS) + std::ios_base::openmode mode = std::ofstream::out; +#else + std::ios_base::openmode mode = std::ofstream::out | std::ofstream::app; +#endif + ::easyloggingpp::logFile = new std::ofstream(::easyloggingpp::kFinalFilename.c_str(), mode); if ((!::easyloggingpp::fileNotOpenedErrorDisplayed) && (!::easyloggingpp::logFile->is_open())) { ::easyloggingpp::internalMessage("Unable to open log file [" + ::easyloggingpp::kFinalFilename + "]"); ::easyloggingpp::fileNotOpenedErrorDisplayed = true; diff --git a/index.php b/index.php index de2012f28..9f9b1998d 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@