From 49a85cf4f2eb16fed9c5a53fb383a8295c7eec23 Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Tue, 5 Mar 2019 19:30:29 -0500 Subject: [PATCH] Enable logging by default and save to cat file. --- lib/uciengine.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/uciengine.cpp b/lib/uciengine.cpp index ede1bf7..cfb8aba 100644 --- a/lib/uciengine.cpp +++ b/lib/uciengine.cpp @@ -21,6 +21,7 @@ #include "uciengine.h" #include +#include #include #include #include @@ -39,7 +40,8 @@ #include "options.h" #include "searchengine.h" -//#define LOG +#define LOG +//#define AVERAGES #if defined(LOG) static bool s_firstLog = true; #endif @@ -132,9 +134,9 @@ void g_uciMessageHandler(QtMsgType type, const QMessageLogContext &context, cons QString format; QTextStream out(&format); if (QLatin1String(context.category) == QLatin1Literal("input")) { - out << "Input:" << endl << msg << endl; + out << "Input: " << msg << endl; } else if (QLatin1String(context.category) == QLatin1Literal("output")) { - out << "Output:" << endl << msg; + out << "Output: " << msg; fprintf(stdout, "%s", qPrintable(msg)); fflush(stdout); } else { @@ -161,17 +163,17 @@ void g_uciMessageHandler(QtMsgType type, const QMessageLogContext &context, cons #if defined(LOG) QString logFilePath = QCoreApplication::applicationDirPath() + QDir::separator() + QCoreApplication::applicationName() + - "_" + QString::number(QCoreApplication::applicationPid()) + ".log"; + "_debug.log"; QFile file(logFilePath); - QIODevice::OpenMode mode = QIODevice::WriteOnly | QIODevice::Text; - if (!s_firstLog) - mode |= QIODevice::Append; - + QIODevice::OpenMode mode = QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append; if (!file.open(mode)) return; QTextStream log(&file); + if (s_firstLog) + log << "Output: log pid " << QCoreApplication::applicationPid() << " at " + << QDateTime::currentDateTime().toString() << "\n"; log << format; s_firstLog = false; #endif @@ -592,7 +594,7 @@ void UciEngine::uciNewGame() m_searchEngine->reset(); m_averageInfo = SearchInfo(); -#if defined(LOG) +#if defined(AVERAGES) if (m_averageInfo.depth != -1) sendAverages(); #endif @@ -615,7 +617,7 @@ void UciEngine::stop() void UciEngine::quit() { //qDebug() << "quit"; -#if defined(LOG) +#if defined(AVERAGES) sendAverages(); #endif Q_ASSERT(m_searchEngine && m_gameInitialized);