Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Oct 25, 2019
1 parent 8c428b9 commit d28fbaf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Binary file modified bin/msvc14_x86/hplayer.exe
Binary file not shown.
43 changes: 19 additions & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d28fbaf

Please sign in to comment.