부스트 (1.55.0)를 사용하고 있습니다. C++ 애플리케이션을 로깅합니다. 나는이 형식 I 소스 파일 이름과 로그가 생성됩니다 줄 번호를 추가 할 수 있도록소스 코드 파일 이름과 행 번호를 인쇄하기위한 부스트 로그
[2014-Jul-15 10:47:26.137959]: <debug> A regular message
의 로그를 생성 할 수있게되었습니다.
[2014-Jul-15 10:47:26.137959]: <debug> [filename:line_no] A regular message
예 :
[2014-Jul-15 10:47:26.137959]: <debug> [helloworld.cpp : 12] A regular message
소스 코드 :
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/attributes/attribute.hpp>
#include <boost/log/attributes/attribute_cast.hpp>
#include <boost/log/attributes/attribute_value.hpp>
#include <boost/make_shared.hpp>
#include <boost/property_tree/ptree.hpp>
namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
void init()
{
logging::add_file_log
(
keywords::file_name = "sample_%N.log", /*< file name pattern >*/
keywords::rotation_size = 10*1024*1204, /*< rotate files every 10 MiB... >*/
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/
keywords::format =
(
boost::log::expressions::stream
<< boost::log::expressions::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d_%H:%M:%S.%f")
<< ": <" << boost::log::trivial::severity << "> "
<< boost::log::expressions::smessage
)
);
}
int main(int, char*[])
{
init();
logging::add_common_attributes();
using namespace logging::trivial;
src::severity_logger<severity_level> lg;
BOOST_LOG_SEV(lg, debug) << "A regular message";
return 0;
}
가능한 [Boost.Log : 지원 파일 이름 및 행 번호] (http://stackoverflow.com/questions/31154429/boost-log-support-file-name-and-line-number) 중복 가능 – Paladin