boost-log

Using boost.log with printf-style macros

烂漫一生 提交于 2019-12-11 02:59:24
问题 I'm working on an application that uses an custom, platform-dependent logger. The application defines some printf-style macros: #define LOG_DEBUG(format, ...) \ logger.log(DEBUG, __FUNCTION__, format, ##__VA_ARGS__) ... The past few days I've been working on moving the application to use boost.log . The biggest problem I'm having is trying to retain this macro format so that only the logger internals need to be changed, since boost's logging API is implemented in iostream-style, i.e. BOOST

Check boost::log filter explicitly?

此生再无相见时 提交于 2019-12-10 12:52:03
问题 I have some trivial logging: BOOST_LOG_TRIVIAL(trace) << make_trace_record(); Now make_trace_record is a somewhat expensive function to call (don't ask why, it's complicated). I want to call it only if the log currently passes filtering. How can I do that? I don't see a way to call the severity filter explicitly. 回答1: Boost.Log filters beforehand; therefore, make_trace_record() will not be called if the severity is not high enough. In order to set the severity filter for the trivial logger,

Boost.Log failing to link with static libraries because of missing code_convert

不想你离开。 提交于 2019-12-10 11:38:11
问题 I'm trying to link Boost.Log statically into my program. Boost.Log has successfully compiled with other modules using bjam. However, when I try to link with my program I'm getting an error: g++ -g -O2 -pthread -o sonar sonar-main.o sonar-config.o sonar-util.o sonar-logger.o /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_system.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_timer.a /home/mike/dev/cpp/boost_1_60_0/stage/lib/libboost_iostreams.a /home/mike/dev/cpp/boost_1_60_0/stage

In Boost Log, how do I format a custom severity_level using a format string?

北城余情 提交于 2019-12-09 18:03:03
问题 I'm using boost log in my C++ program, and I have a custom severity_logger< severity_level > using a severity_level enum that I defined. Then I create my log sink with the format string "%TimeStamp% [%ThreadID%] %Severity% %Module% - %Message%" but it doesn't display the severity where I have %Severity% but instead is just blank in that position. For example, 2013-07-29 10:31 [0xDEADBEEF] my.Module - Hello World . What do I need to do in my format string to make it display the severity level?

How does the “lazy evaluation” of Boost Log's trivial loggers work?

故事扮演 提交于 2019-12-08 19:11:52
问题 [ Follows up Check boost::log filter explicitly? ] The following example uses the trivial logger from Boost Log. It outputs 1 , showing that expensive() is only called once. How does it work? Why is expensive() not called? Live On Coliru #include <iostream> #include <boost/log/expressions.hpp> #include <boost/log/trivial.hpp> int count = 0; int expensive() { return ++count; } int main() { boost::log::core::get()->set_filter( boost::log::trivial::severity >= boost::log::trivial::warning );

BOOST_LOG_TRIVIAL ( severity ) << … does not redirect to a file

橙三吉。 提交于 2019-12-08 03:20:25
问题 We are using the simplest version of boost.log v2 with BOOST_LOG_TRIVIAL ( severity ) << ... For the moment we would not like to create a separate sink or output file, sometimes redirecting the console output to a file is good enough for our purposes. Under CentOs 7 with boost.log v1.59 we have noticed that many times the output is not redirected but instead lost completely when using various redirection options like <executable> 2>&1 out.txt etc. The file ends up with zero length and no

How to use a compressor Boost::Iostreams filter as a sink in Boost::Log

て烟熏妆下的殇ゞ 提交于 2019-12-07 16:13:54
问题 I'm trying to compress log files created using the Boost Log library instantaneously by utilizing boost::iostreams::gzip_compressor . So when I call BOOST_LOG() , output gets compressed on-the-fly. Here's what I tried so far: #include <fstream> #include <iostream> #include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/filtering_streambuf.hpp> #include <boost/iostreams/stream.hpp> #include <boost/iostreams/filter/gzip.hpp> #include <boost/smart_ptr/shared_ptr.hpp> #include

Boost Log changing the default logging::core formatter?

风格不统一 提交于 2019-12-07 15:36:25
问题 I'm using Boost v1.54 and I would like to simply change the default sink format of logging::core but haven't found a way to do so. In the Log Record Formatting documentation they only show how to change the format for custom sinks e.g. log files and not the default one? Is there a way to globally set the default format in Boost Log? This is what they do: void init() { logging::add_file_log ( keywords::file_name = "sample_%N.log", keywords::rotation_size = 10 * 1024 * 1024, keywords::time

boost log file not written to

北战南征 提交于 2019-12-06 19:03:08
问题 I've been struggling with boost log for a while now - I got their simple example writing to a log file (http://boost-log.sourceforge.net/libs/log/example/doc/tutorial_file.cpp). However, when I try to copy that code into a 'Logger' class, I can't get it to write to the log file. I can see the file default.log get created, but there is nothing in it. I'm on debian 7 64bit. Everything compiles fine - compile line is: g++ -o build/Logger.o -c -std=c++11 -Wall -g -O0 -DBOOST_LOG_DYN_LINK -DDEBUG

boost log format single attribute with logging::init_from_stream

早过忘川 提交于 2019-12-06 10:53:10
问题 When I set up format params in code, to format date time output I can use something like this logging::formatter simpleFormat(expr::format("%1% %2%") % expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%H:%M:%S") % expr::smessage ); But when I initialize logger with a config file, I can specify format only in attributes position notation, not their format details. so, this line in a boost log config file Format="[%TimeStamp%]: %Message%" produces output: [2015-Feb-06 09:32:27