do not print debug log in release mode

Add -d argument to print debug log in release mode.
This commit is contained in:
Le Tan 2018-01-26 23:08:18 +08:00
parent 30c69fc148
commit 4267ea54c8
2 changed files with 22 additions and 1 deletions

View File

@ -22,6 +22,9 @@ VPalette *g_palette;
// 5MB log size. // 5MB log size.
#define MAX_LOG_SIZE 5 * 1024 * 1024 #define MAX_LOG_SIZE 5 * 1024 * 1024
// Whether print debug log in RELEASE mode.
bool g_debugLog = false;
QFile g_logFile; QFile g_logFile;
static void initLogFile(const QString &p_file) 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) 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(); QByteArray localMsg = msg.toUtf8();
QString header; QString header;
@ -59,6 +68,9 @@ void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &m
case QtFatalMsg: case QtFatalMsg:
header = "Fatal:"; header = "Fatal:";
default:
break;
} }
#if defined(QT_NO_DEBUG) #if defined(QT_NO_DEBUG)
@ -72,7 +84,6 @@ void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &m
g_logFile.close(); g_logFile.close();
abort(); abort();
} }
#else #else
std::string fileStr = QFileInfo(context.file).fileName().toStdString(); std::string fileStr = QFileInfo(context.file).fileName().toStdString();
const char *file = fileStr.c_str(); const char *file = fileStr.c_str();
@ -135,6 +146,12 @@ int main(int argc, char *argv[])
g_config = &vconfig; g_config = &vconfig;
#if defined(QT_NO_DEBUG) #if defined(QT_NO_DEBUG)
for (int i = 1; i < argc; ++i) {
if (!qstrcmp(argv[i], "-d")) {
g_debugLog = true;
}
}
initLogFile(vconfig.getLogFilePath()); initLogFile(vconfig.getLogFilePath());
#endif #endif

View File

@ -1065,6 +1065,10 @@ QStringList VUtils::filterFilePathsToOpen(const QStringList &p_files)
{ {
QStringList paths; QStringList paths;
for (int i = 0; i < p_files.size(); ++i) { for (int i = 0; i < p_files.size(); ++i) {
if (p_files[i].startsWith('-')) {
continue;
}
QString path = validFilePathToOpen(p_files[i]); QString path = validFilePathToOpen(p_files[i]);
if (!path.isEmpty()) { if (!path.isEmpty()) {
paths.append(path); paths.append(path);