diff --git a/bin/msvc14_x86/hplayer.exe b/bin/msvc14_x86/hplayer.exe index b8c6880..caee958 100644 Binary files a/bin/msvc14_x86/hplayer.exe and b/bin/msvc14_x86/hplayer.exe differ diff --git a/src/main.cpp b/src/main.cpp index 2c4c86f..1345306 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,51 +7,46 @@ #define LOG_LEVEL 0 void qLogHandler(QtMsgType type, const QMessageLogContext & ctx, const QString & msg) { - // QtDebugMsg = 0 - // QtInfoMsg = 4 if (type < LOG_LEVEL) return; - char szType[16]; - switch (type) { - case QtDebugMsg: - strcpy(szType, "DEBUG"); - break; - case QtInfoMsg: - strcpy(szType, "INFO "); - break; - case QtWarningMsg: - strcpy(szType, "WARN "); - break; - case QtCriticalMsg: - strcpy(szType, "ERROR"); - break; - case QtFatalMsg: - strcpy(szType, "FATAL"); + //enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtInfoMsg, QtSystemMsg = QtCriticalMsg }; + static char s_types[5][6] = {"DEBUG", "WARN ", "ERROR", "FATAL", "INFO "}; + const char* szType = "DEBUG"; + if (type < 5) { + szType = s_types[(int)type]; } - QString strLog = QString::asprintf("[%s] [%s]: %s [%s:%d-%s]\n", + +#ifdef QT_NO_DEBUG + QString strLog = QString::asprintf("[%s][%s]: %s\n", + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toLocal8Bit().data(), + szType, + msg.toLocal8Bit().data()); +#else + QString strLog = QString::asprintf("[%s][%s]: %s [%s:%d-%s]\n", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toLocal8Bit().data(), szType, msg.toLocal8Bit().data(), ctx.file,ctx.line,ctx.function); +#endif QString strLogfile = "qt.log"; static FILE* s_fp = NULL; - if (!s_fp) { - s_fp = fopen(strLogfile.toLocal8Bit().data(), "a"); - } - if (s_fp) { fseek(s_fp, 0, SEEK_END); if (ftell(s_fp) > (2 << 20)) { fclose(s_fp); - s_fp = fopen(strLogfile.toLocal8Bit().data(), "w"); + s_fp = NULL; } } + if (!s_fp) { + s_fp = fopen(strLogfile.toLocal8Bit().data(), "w"); + } + if (s_fp) { fputs(strLog.toLocal8Bit().data(), s_fp); }