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 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