Boost:Log
bjam build command
You can define configuration macros in the bjam command line, like this:
$ bjam --with-log variant=release define=BOOST_LOG_WITHOUT_EVENT_LOG define=BOOST_LOG_USE_WINNT6_API stage
File name format
파일명에 날짜_시간_넘버링
을 적용하고 싶을 경우 아래와 같이 입력하면 된다.
Severity format attribute
Format에 %Severity%
속성을 사용하고 싶을 경우 아래와 같이 적용하면 된다.
#include <boost/log/utility/setup/formatter_parser.hpp>
// ...
boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");
Common attributes
Format에서 %TimeStamp%
와 같은 기본 속성을 사용하고 싶을 경우 아래와 같이 초기화 해야 한다.
Custom sink
Simple example:
#include <boost/log/trivial.hpp>
#include <boost/log/sinks/basic_sink_backend.hpp>
#include <boost/log/attributes/value_extraction.hpp>
#include <boost/log/sinks/async_frontend.hpp>
// ...
class app_launcher: public boost::log::sinks::basic_formatted_sink_backend<char,
boost::log::sinks::synchronized_feeding>
{
public:
// The function consumes the log records that come from the frontend
void consume(boost::log::record_view const& rec, string_type const& command_line)
{
std::cout << command_line << std::endl;
}
};
// ...
typedef sinks::synchronous_sink<app_launcher> sink_t;
boost::shared_ptr<sink_t> sink(new sink_t());
boost::shared_ptr<boost::log::core> logc = boost::log::core::get();
logc->add_sink(sink);
Warning
BOOST_LOG_WITHOUT_EVENT_LOG
In case if message compiler detection fails for some reason, you can explicitly disable support for event log backend by defining the BOOST_LOG_WITHOUT_EVENT_LOG
configuration macro when building the library.
BOOST_LOG_USE_WINNT6_API
Affects compilation of both the library and users' code. This macro is Windows-specific. If defined, the library makes use of the Windows NT 6 (Vista, Server 2008) and later APIs to generate more efficient code. This macro will also enable some experimental features of the library. Note, however, that the resulting binary will not run on Windows prior to NT 6. In order to use this feature Platform SDK 6.0 or later is required.
Troubleshooting
Boost.log를 사용하면서 발생하는 문제점 및 해결 방법을 정리한다.
swprintf not declared
MinGW를 사용할 경우 아래와 같은 메시지가 출력될 수 있다.
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:159: error:
'::swprintf' has not been declared
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:166: error:
'::vswprintf' has not been declared
이 경우 stdio.h
앞에 아래와 같이 입력한다.
undefined reference to boost::detail::set_tss_data
See also: Boost:Thread#Troubleshooting
See also
Favorite site
- Boost.log Advaced 사용법
- boost log 사용하기
- Adding more information to log: Attributes
- A simple, customized logger, based on Boost.Log v2
Documentation
- Chapter 1. Boost.Log v2
- Setting up sinks
- [추천] Utilities
- Attributes
- Filtering revisited
- Log record formatting
- [추천] Sink backends