$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] [log] translating 3rd party logging messages
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2014-07-08 08:27:30
Hello,
shown my translator for Qt using boost.log:
void qt_message_translator(QtMsgType type, const QMessageLogContext 
&context, const QString &msg)
{
     QString const context_message =
               QString("Qt [")
             + context.function + " ("
             + context.file + ":"
             + QString::number(context.line)
             + ")] ";
     QByteArray const ctx_msg = context_message.toUtf8();
     QByteArray const qt_msg  = msg.toUtf8();
     boost::log::sources::severity_logger<severity_level> slg;
     switch (type) {
     case QtDebugMsg:
         BOOST_LOG_SEV(slg, debug) << ctx_msg.constData() << 
qt_msg.constData();
         break;
     case QtWarningMsg:
         BOOST_LOG_SEV(slg, warning) << ctx_msg.constData() << 
qt_msg.constData();
         break;
     case QtCriticalMsg:
         BOOST_LOG_SEV(slg, error) << ctx_msg.constData() << 
qt_msg.constData();
         break;
     case QtFatalMsg:
         BOOST_LOG_SEV(slg, fatal) << ctx_msg.constData() << 
qt_msg.constData();
         break;
     default:
         BOOST_LOG_SEV(slg, fatal) << ctx_msg.constData() << 
qt_msg.constData();
         break;
     }
}
...
qInstallMessageHandler(qt_message_translator);
The problem is more of cosmetic nature; the logging format output is 
different from what is used normally - it looks alien. Since the context 
data is available I assume I can write an own logging source 
writing/fill the log records filled with the context information. 
Additionally I want to add a "Scope" or "Library" flag "Qt" (Scope may 
be not the best choise since it's used in another context). But I didn't 
find an example in the boost.log module to find the entry; is writing an 
own source the right way? How to use it in the qt_message_translator?
Thanks,
Olaf