From 4267ea54c86534b7bd87ab77656ea883a4889fc6 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Fri, 26 Jan 2018 23:08:18 +0800 Subject: [PATCH] do not print debug log in release mode Add -d argument to print debug log in release mode. --- src/main.cpp | 19 ++++++++++++++++++- src/utils/vutils.cpp | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6ea2635b..1c872ce4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,9 @@ VPalette *g_palette; // 5MB log size. #define MAX_LOG_SIZE 5 * 1024 * 1024 +// Whether print debug log in RELEASE mode. +bool g_debugLog = false; + QFile g_logFile; static void initLogFile(const QString &p_file) @@ -37,6 +40,12 @@ static void initLogFile(const QString &p_file) void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg) { +#if defined(QT_NO_DEBUG) + if (!g_debugLog && type == QtDebugMsg) { + return; + } +#endif + QByteArray localMsg = msg.toUtf8(); QString header; @@ -59,6 +68,9 @@ void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &m case QtFatalMsg: header = "Fatal:"; + + default: + break; } #if defined(QT_NO_DEBUG) @@ -72,7 +84,6 @@ void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &m g_logFile.close(); abort(); } - #else std::string fileStr = QFileInfo(context.file).fileName().toStdString(); const char *file = fileStr.c_str(); @@ -135,6 +146,12 @@ int main(int argc, char *argv[]) g_config = &vconfig; #if defined(QT_NO_DEBUG) + for (int i = 1; i < argc; ++i) { + if (!qstrcmp(argv[i], "-d")) { + g_debugLog = true; + } + } + initLogFile(vconfig.getLogFilePath()); #endif diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 4092068a..82786d45 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -1065,6 +1065,10 @@ QStringList VUtils::filterFilePathsToOpen(const QStringList &p_files) { QStringList paths; for (int i = 0; i < p_files.size(); ++i) { + if (p_files[i].startsWith('-')) { + continue; + } + QString path = validFilePathToOpen(p_files[i]); if (!path.isEmpty()) { paths.append(path);