Skip to content

Commit

Permalink
closes #11 - Now you can clean logs every time you run application
Browse files Browse the repository at this point in the history
  • Loading branch information
abumq committed Jan 13, 2013
1 parent be9206f commit 9301d33
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions easylogging++.h
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> //
// http://www.icplusplus.com //
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
include_once "../../format.php";
global $webAddr;
$currentVersion = "v3.17";
$currentVersion = "v3.18";
?>
<script language='javascript'>
document.title='EasyLogging++ - C++ Tools';
Expand Down
Binary file modified samples/bin/many_logs.cpp.bin
Binary file not shown.
Binary file modified samples/bin/time_tracker.cpp.bin
Binary file not shown.
Binary file modified samples/bin/time_waster.cpp.bin
Binary file not shown.

0 comments on commit 9301d33

Please sign in to comment.