Skip to content

Commit

Permalink
Merge pull request #624 from adah1972/file_rolling_at_flush
Browse files Browse the repository at this point in the history
File rolling at flush
  • Loading branch information
abumq committed Apr 1, 2018
2 parents 56876a6 + 8eabcc3 commit f0d0a71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ Although this is a rare situation but if you wish to get list of all the logger
### Sharing Logging Repository
For advance logging, you can share your logging repositories to shared or static libraries, or even from library to application. This is rare case but a very good example is as follows;

Let's say we have an application that uses easylogging++ and has it's own configuration, now you are importing library that uses easylogging++ and wants to access logging repository of main application. You can do this using two ways;
Let's say we have an application that uses easylogging++ and has its own configuration, now you are importing library that uses easylogging++ and wants to access logging repository of main application. You can do this using two ways;

* Instead of using `INITIALIZE_EASYLOGGINGPP` you use `SHARE_EASYLOGGINGPP(access-function-to-repository)`
* Instead of using `INITIALIZE_EASYLOGGINGPP` you use `INITIALIZE_NULL_EASYLOGGINGPP` and then `el::Helpers::setStorage(el::base::type::StoragePointer)`
Expand Down Expand Up @@ -921,9 +921,9 @@ In order to install this handler, use `void Helpers::installPerformanceTrackingC
### Log File Rotating
Easylogging++ has ability to roll out (or throw away / rotate) log files if they reach certain limit. You can configure this by setting `Max_Log_File_Size`. See Configuration section above.
If you are having failure in log-rollout, you may have failed to add flag i.e, `el::LoggingFlags::StrictLogFileSizeCheck`.
Rollout checking happens when Easylogging++ flushes the log file, or, if you have added the flag `el::LoggingFlags::StrictLogFileSizeCheck`, at each log output.
This feature has it's own section in this reference manual because you can do stuffs with the file being thrown away. This is useful, for example if you wish to back this file up etc.
This feature has its own section in this reference manual because you can do stuffs with the file being thrown away. This is useful, for example if you wish to back this file up etc.
This can be done by using `el::Helpers::installPreRollOutCallback(const PreRollOutCallback& handler)` where `PreRollOutCallback` is typedef of type `std::function<void(const char*, std::size_t)>`. Please note following if you are using this feature
There is a [sample](/samples/STL/logrotate.cpp) available that you can use as basis.
Expand Down
6 changes: 3 additions & 3 deletions src/easylogging++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ void Logger::flush(Level level, base::type::fstream_t* fs) {
if (iter != m_unflushedCount.end()) {
iter->second = 0;
}
Helpers::validateFileRolling(this, level);
}
}

Expand Down Expand Up @@ -756,10 +757,9 @@ std::size_t File::getSizeOfFile(base::type::fstream_t* fs) {
if (fs == nullptr) {
return 0;
}
std::streampos currPos = fs->tellg();
fs->seekg(0, fs->end);
// Since the file stream is appended to or truncated, the current
// offset is the file size.
std::size_t size = static_cast<std::size_t>(fs->tellg());
fs->seekg(currPos);
return size;
}

Expand Down

0 comments on commit f0d0a71

Please sign in to comment.