I don't think you can do this with BOOST_LOG_TRIVIAL
. The trivial logger uses a underlying boost::sources::logger
instead of boost::sources::wlogger
, you can see that from trivial.hpp and trivial.cpp in the boost source file, and I can't see how we can change it unless we modify the source code. If you use a wlogger
, it would work. Here is an example:
#include <iostream>
#include <string>
#include <boost/log/sources/logger.hpp>
#include <boost/log/common.hpp>
namespace src = boost::log::sources;
class CWindowClassId
{
public:
// ...
friend std::wostream& operator<< (std::wostream& os, CWindowClassId const& classId)
{
os << classId.ws;
return os;
}
public:
std::wstring ws;
};
int main(int argc, char* argv[])
{
src::wlogger lg;
CWindowClassId id;
id.ws = L"wide char";
BOOST_LOG(lg) << "Hello, World! This is a wide character message."<<id;
return 0;
}