82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
#include <myx/backports/qt/common.hpp>
|
|
#include <myx/core/config.hpp>
|
|
|
|
#include <myx/qt/message_logger.hpp>
|
|
|
|
#include <QtDebug>
|
|
|
|
namespace myx {
|
|
|
|
namespace qt {
|
|
|
|
MessageLoggersList messageLoggersList;
|
|
|
|
void message_logger_handler( QtMsgType type, const QMessageLogContext& context, const QString& msg )
|
|
{
|
|
if ( messageLoggersList.isEmpty() )
|
|
{
|
|
QByteArray localMsg = msg.toLocal8Bit();
|
|
const char* file = context.file != nullptr ? context.file : "";
|
|
const char* function = context.function != nullptr ? context.function : "";
|
|
switch ( type )
|
|
{
|
|
case QtDebugMsg:
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
|
// fprintf( stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
|
#endif
|
|
break;
|
|
case QtInfoMsg:
|
|
#ifndef QT_NO_INFO_OUTPUT
|
|
// fprintf( stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
|
#endif
|
|
break;
|
|
case QtWarningMsg:
|
|
#ifndef QT_NO_WARNING_OUTPUT
|
|
// fprintf( stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
|
#endif
|
|
break;
|
|
case QtCriticalMsg:
|
|
// fprintf( stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
|
// fprintf( stderr, "%s\n", localMsg.constData() );
|
|
// break;
|
|
case QtFatalMsg:
|
|
// fprintf( stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
|
break;
|
|
} // switch
|
|
}
|
|
else
|
|
{
|
|
switch ( type )
|
|
{
|
|
case QtDebugMsg:
|
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
|
{ if ( m->isEnabled() ) { m->debug( context, msg ); } }
|
|
break;
|
|
case QtInfoMsg:
|
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
|
{ if ( m->isEnabled() ) { m->info( context, msg ); } }
|
|
break;
|
|
case QtWarningMsg:
|
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
|
{ if ( m->isEnabled() ) { m->warning( context, msg ); } }
|
|
break;
|
|
case QtCriticalMsg:
|
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
|
{ if ( m->isEnabled() ) { m->critical( context, msg ); } }
|
|
break;
|
|
case QtFatalMsg:
|
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
|
{ if ( m->isEnabled() ) { m->fatal( context, msg ); } }
|
|
break;
|
|
} // switch
|
|
}
|
|
} // message_logger_handler
|
|
|
|
} // namespace qt
|
|
|
|
} // namespace myx
|