Comments (4)
@christapley Thank you for the reproducer, although I'm not sure your case is the same as the OP's. In the original problem description, the log message size is definitely smaller than the rotation_size
limit, and it looks like every time a log file is open on his system, it is already too large to fit a new record.
In any case, I have committed a fix for your reproducer in b5c4277 and also an additional safeguard in 407260f. I'm not sure it'll fix the OP's problem, but I haven't heard from him, so I'm closing this report.
from log.
Please, provide a minimal compilable code sample that reproduces the problem.
from log.
From your debugging gif, it looks like you have lots of log files in the logging directory, and the backend iterates over them trying to find the log file name that is not yet used. This isn't an infinite loop, unless you have 4 billion log files in the directory.
from log.
I've ran into the same problem. It was introduced by #179
#include <vector>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
void init_logging()
{
logging::register_simple_formatter_factory<logging::trivial::severity_level, char>("Severity");
auto file = logging::add_file_log(
keywords::file_name = "sample_%N.log", //
keywords::target = "./", //
keywords::target_file_name = "sample_%N.log", //
keywords::open_mode = std::ios_base::app, //
keywords::auto_flush = true, //
keywords::rotation_size = 500*1024, //
keywords::max_size = 6*1024*1024, //
keywords::max_files = 6,
keywords::format =
"%LineID%. [%TimeStamp%][%ThreadID%] [%Severity%] - %Message%");
file->locked_backend()->scan_for_files();
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
logging::add_common_attributes();
}
int main()
{
init_logging();
std::vector<char> value(static_cast<size_t>(1024*1024), 'a');
value.push_back('\0');
BOOST_LOG_TRIVIAL(info) << value.data();
BOOST_LOG_TRIVIAL(info) << value.data();
BOOST_LOG_TRIVIAL(info) << value.data();
BOOST_LOG_TRIVIAL(info) << value.data();
}
If the log line exceeds the rotation size then we'll be stuck in an infinite loop.
This is a possible resolution
diff --git a/src/text_file_backend.cpp b/src/text_file_backend.cpp
index 8b8920e..8b0b6a7 100644
--- a/src/text_file_backend.cpp
+++ b/src/text_file_backend.cpp
@@ -1480,8 +1480,10 @@ BOOST_LOG_API void text_file_backend::consume(record_view const& rec, string_typ
m_pImpl->m_IsFirstFile = false;
// Check the file size before invoking the open handler, as it may write more data to the file
+ // But don't rotate the file if the current log message itself exceeds the rotate file size
m_pImpl->m_CharactersWritten = static_cast< std::streamoff >(m_pImpl->m_File.tellp());
- if (m_pImpl->m_CharactersWritten + formatted_message.size() >= m_pImpl->m_FileRotationSize)
+ if (m_pImpl->m_CharactersWritten + formatted_message.size() >= m_pImpl->m_FileRotationSize
+ && formatted_message.size() < m_pImpl->m_FileRotationSize)
{
// Avoid running the close handler, as we haven't run the open handler yet
struct close_handler_backup_guard
Any hints on what sort of solution boost would accept @Lastique ?
from log.
Related Issues (20)
- Boost.Log rotation may throw boost::filesystem::filesystem_error HOT 10
- How to add timezone info for log entries and log filename HOT 3
- Formatting TimeStamp HOT 1
- Boost 1.82, boost\Log\trivial unresolved external symbol error if included after curl HOT 3
- Log Formatting [Conan 2.x, C++20, Boost 1.83] HOT 2
- 1.82.0 compiled for XP uses AcquireSRWLockExclusive HOT 2
- How to append log to same log file after program restarts? HOT 1
- CMake integration for Xcode universal 2 builds HOT 1
- boost日志在动态库里被使用,再次在主程序中使用会崩溃 HOT 1
- Boost stopped printing logs after changing the system time HOT 4
- Redundent call to boost_install() HOT 1
- An infinite loop occurs when boost writes to the log file (Debug Mode, Medium size file) HOT 1
- Consider switching dependency from MPL to MP11 HOT 2
- Please consider improving the documentation and examples HOT 1
- Linking failure after upgrading boost to 1.82 from 1.69 HOT 2
- advanced instruction sets HOT 1
- About Scope %f HOT 1
- boost/1.85.0 compile issues with msm::front::state_machine_def on llvm/clang++ 18.1.5 with std=c++20 HOT 4
- GetCurrentThreadId is called everytime even not extracting current_thread_id HOT 6
- Crash when FreeLibrary a dll uses Boost.Log HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log.