boost-log

How can I manually flush a boost log?

谁都会走 提交于 2019-12-04 10:24:15
I'm playing with Boost.Log in boost 1.54.0 to see if it is a viable option for my application. In general, I don't have a problem with the buffering, so I'm not looking to turn on auto_flush or anything... but I noticed that messages that are logged before I call fork() are duplicated, and I'm wondering if it's because they are buffered, the buffer gets duplicated when the process image is copied, and then both processes eventually write their buffer copies to the log file... So basically, I'd like to just do a manual flush on the log, one time only, immediately before I call fork() in order

Boost Log causes crash when trying first log statement (when not Administrator)

泪湿孤枕 提交于 2019-12-04 09:55:50
I am trying to deploy my application right now, which uses Boost Log (Boost 1.58). It is a simple console app, being run in Windows 7. Logging works perfectly fine on my personal desktop. However, when I deploy the application to a Win7 virtual machine, it crashes upon my first log statement: boost::log::sources::severity_logger<SeverityLevel> slg; BOOST_LOG_SEV(slg, SeverityLevel::Notification) << L"Application loaded"; // <-- Crash here The log directory gets created, but the log file never gets created and the application crashes. I have tried a logfile directory in my %APPDATA% directory,

Enable Boost.Log only on debug

霸气de小男生 提交于 2019-12-04 08:01:38
I need a logger for debug purpose and I'm using Boost.Log (1.54.0 with a patch in the boost.org homepage). It's all fine I've created some macro like this: #define LOG_MESSAGE( lvl ) BOOST_LOG_TRIVIAL( lvl ) Now is that a way that LOG_MESSAGE( lvl ) is expaneded in BOOST_LOG_TRIVIAL( lvl ) only in debug mode and ignore in release? for example: LOG_MESSAGE( critical ) << "If I read this message we're in debug mode" edit My first attempt is to create a nullstream... I think that in release mode compiler will optimize it... #if !defined( NDEBUG ) #include <boost/log/trivial.hpp> #define LOG

How to redirect Boost.Log to file

╄→гoц情女王★ 提交于 2019-12-03 05:26:49
I want a simple log file in a concurrent application. I've download Boost.Log v2.0 and using compiled it with Boost 1.53.0 . The problem is that Boost.Log output on console. I'm using BOOST_LOG_TRIVIAL(trace) . Is there a nice way to redirect BOOST_LOG_TRIVIAL to a file? m0nhawk You can make BOOST_LOG_TRIVIAL use a file with (assuming that namespace logging = boost::log; : #include <boost/log/core.hpp> #include <boost/log/trivial.hpp> #include <boost/log/expressions.hpp> #include <boost/log/utility/setup/file.hpp> void init() { logging::add_file_log("sample.log"); logging::core::get()->set

boost.log std::exception formatter unable to find operator<< overload in own namespace

南楼画角 提交于 2019-12-02 17:07:21
问题 I have created a simple formatter for boost.log like shown in this example for std::exception . Now if i want to use the overloaded operator, which is defined in my own namespace, log is unable to find the overload. Some code: namespace my_space { template< typename CharT, typename TraitsT > std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, std::exception const& e) { // some printout stuff here strm << e.what(); return strm; } } // namespace my

boost::log add_file_log not writing if app exits with CTRL_CLOSE_EVENT

巧了我就是萌 提交于 2019-12-02 14:49:35
问题 I'm on Windows 7, using boost::log in v1.54 in a console application. I'm using add_file_log() with rotation, which works fine as long as my main() function exits. But if the app is terminated externally with powershell CloseMainWindow(), the log file never gets written. I've set up a windows control handler using SetConsoleCtrlHandler(), and can trap CTRL_CLOSE_EVENT, but I don't know if there's a boost::log method I can call to force the log file to write prior to my app exiting. Does

boost::log add_file_log not writing if app exits with CTRL_CLOSE_EVENT

时光怂恿深爱的人放手 提交于 2019-12-02 10:16:10
I'm on Windows 7, using boost::log in v1.54 in a console application. I'm using add_file_log() with rotation, which works fine as long as my main() function exits. But if the app is terminated externally with powershell CloseMainWindow(), the log file never gets written. I've set up a windows control handler using SetConsoleCtrlHandler(), and can trap CTRL_CLOSE_EVENT, but I don't know if there's a boost::log method I can call to force the log file to write prior to my app exiting. Does anyone have a solution for this? Thanks, Rob Two thing you may want to look at. The following is based on my

boost.log std::exception formatter unable to find operator<< overload in own namespace

白昼怎懂夜的黑 提交于 2019-12-02 09:29:51
I have created a simple formatter for boost.log like shown in this example for std::exception . Now if i want to use the overloaded operator, which is defined in my own namespace, log is unable to find the overload. Some code: namespace my_space { template< typename CharT, typename TraitsT > std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, std::exception const& e) { // some printout stuff here strm << e.what(); return strm; } } // namespace my_space But if i move (Stroustrup please don't shot me, it was only for testing) the overload into std

How to log line number of coder in boost log 2.0?

穿精又带淫゛_ 提交于 2019-11-30 19:07:01
Can I use LineID attribute for this? I hope I could use sink::set_formatter to do this instead of using __LINE__ and __FILE__ in each log statement. I struggled with this, until I found this snippet #define LFC1_LOG_TRACE(logger) \ BOOST_LOG_SEV(logger, trivial::trace) << "(" << __FILE__ << ", " << __LINE__ << ") " Works like a charm The LineID attribute is a sequential number that is incremented for each logging message. So you can't use that. You can use attributes to log the line numbers etc. This allows you flexible formatting using the format string, whereas using Chris' answer your

Boost log severity_logger init_from_stream

拟墨画扇 提交于 2019-11-30 12:12:00
I am using boost 1.54.0. Below you can find a minimum example that illustrates my problem. I use the severity_logger of boost log. I want to configure my sinks from a stream. (In the following example I use a stringstream. In my real application the stream comes from a file.) I want to use the %Severity% for output or filtering purposes. My problem is: If I use it as given in the example below, %Severity% is empty. %LineID% and %Message% are filled as expected. If I set up a sink as given in the outcommented lines, it works as expected. Any ideas? #include <boost/log/sources/severity_logger