A little change in message logging

This commit is contained in:
Abs62 2017-07-25 18:28:03 +03:00
parent a0c60d0eb9
commit 4fe34a95f5

18
main.cc
View file

@ -29,6 +29,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QByteArray>
#include <QString> #include <QString>
#include "gddebug.hh" #include "gddebug.hh"
@ -43,13 +44,14 @@ void gdMessageHandler( QtMsgType type, const QMessageLogContext &context, const
{ {
Q_UNUSED( context ); Q_UNUSED( context );
QString message( mess ); QString message( mess );
const char * msg = message.toUtf8().constData(); QByteArray msg = message.toUtf8().constData();
#else #else
void gdMessageHandler( QtMsgType type, const char *msg ) void gdMessageHandler( QtMsgType type, const char *msg_ )
{ {
QString message = QString::fromUtf8( msg ); QString message = QString::fromUtf8( msg_ );
QByteArray msg = QByteArray::fromRawData( msg_, strlen( msg_ ) );
#endif #endif
@ -59,21 +61,21 @@ void gdMessageHandler( QtMsgType type, const char *msg )
if( logFile.isOpen() ) if( logFile.isOpen() )
message.insert( 0, "Debug: " ); message.insert( 0, "Debug: " );
else else
fprintf(stderr, "Debug: %s\n", msg); fprintf(stderr, "Debug: %s\n", msg.constData());
break; break;
case QtWarningMsg: case QtWarningMsg:
if( logFile.isOpen() ) if( logFile.isOpen() )
message.insert( 0, "Warning: " ); message.insert( 0, "Warning: " );
else else
fprintf(stderr, "Warning: %s\n", msg); fprintf(stderr, "Warning: %s\n", msg.constData());
break; break;
case QtCriticalMsg: case QtCriticalMsg:
if( logFile.isOpen() ) if( logFile.isOpen() )
message.insert( 0, "Critical: " ); message.insert( 0, "Critical: " );
else else
fprintf(stderr, "Critical: %s\n", msg); fprintf(stderr, "Critical: %s\n", msg.constData());
break; break;
case QtFatalMsg: case QtFatalMsg:
@ -84,7 +86,7 @@ void gdMessageHandler( QtMsgType type, const char *msg )
logFile.flush(); logFile.flush();
} }
else else
fprintf(stderr, "Fatal: %s\n", msg); fprintf(stderr, "Fatal: %s\n", msg.constData());
abort(); abort();
#if QT_VERSION >= QT_VERSION_CHECK( 5, 5, 0 ) #if QT_VERSION >= QT_VERSION_CHECK( 5, 5, 0 )
@ -92,7 +94,7 @@ void gdMessageHandler( QtMsgType type, const char *msg )
if( logFile.isOpen() ) if( logFile.isOpen() )
message.insert( 0, "Info: " ); message.insert( 0, "Info: " );
else else
fprintf(stderr, "Info: %s\n", msg); fprintf(stderr, "Info: %s\n", msg.constData());
break; break;
#endif #endif
} }