how to use ros::console::print

asked 2017-04-26 04:35:04 -0600

Simon Schmeisser gravatar image

Hi

I'm trying to set up a message handler that routes Qt messages to ros::console logging system. It is quite straightforward following the example given here: http://doc.qt.io/qt-5/qtglobal.html#q...

void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
    QByteArray localMsg = msg.toLocal8Bit();
    switch (type) {
        case QtDebugMsg:
            ROS_DEBUG("%s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtInfoMsg:
            ROS_INFO("%s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtWarningMsg:
            ROS_WARN("%s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtCriticalMsg:
            ROS_ERROR("%s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtFatalMsg:
            ROS_FATAL("%s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            abort();
        }
}

however as the Qt functions already provide context information (file, line, function) I would prefer to have these passed along to ros console instead of having ROS_ERROR at the location of the wrapper.

It looks like ros::console::print is the way to go, but there are too many parameters that I fail to deduce from the macros. Did anybody manage?

Thanks Simon

edit retag flag offensive close merge delete