BOOST Log 使用 Unicode

#include "stdafx.h"
#include <iostream>
#include <boost/log/common.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup.hpp>

using namespace std;
namespace logging = boost::log::BOOST_LOG_VERSION_NAMESPACE;
namespace src = boost::log::BOOST_LOG_VERSION_NAMESPACE::sources;
namespace sinks = boost::log::BOOST_LOG_VERSION_NAMESPACE::sinks;
namespace keywords = boost::log::BOOST_LOG_VERSION_NAMESPACE::keywords;
namespace expr = boost::log::BOOST_LOG_VERSION_NAMESPACE::expressions;

int _tmain(int argc, _TCHAR* argv[])
{
	//返回值为前端槽
	BOOST_AUTO(console_sink,logging::add_console_log<wchar_t>());
	console_sink->set_formatter(
		expr::format<wchar_t>(L"[%1%][%2%]")
		%logging::trivial::severity
		%expr::wmessage
	);
	//获取后端槽设置直接写出
	console_sink->locked_backend()->auto_flush(true);

	locale curloc=locale::global(locale("chs"));
	using namespace logging::trivial;
	src::wseverity_logger< severity_level > lg;
	BOOST_LOG_SEV(lg, trace) << L"测试:A trace severity message";
	BOOST_LOG_SEV(lg, debug) << L"测试:A debug severity message";
	BOOST_LOG_SEV(lg, info) << L"测试:An informational severity message";
	BOOST_LOG_SEV(lg, warning) << L"测试:A warning severity message";
	BOOST_LOG_SEV(lg, error) << L"测试:An error severity message";
	BOOST_LOG_SEV(lg, fatal) << L"测试:A fatal severity message";
	BOOST_LOG(lg)<<L"测试BOOST_LOG宏";
	locale::global(curloc);
	return 0;
}

输出中文需要设置本地化

BOOST_LOG输出级别为trace

add_console_log返回值为synchronous sink frontend

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值