Skip to content

Commit

Permalink
Enable logging by default and save to cat file.
Browse files Browse the repository at this point in the history
  • Loading branch information
adtreat committed Mar 6, 2019
1 parent b5c1e58 commit 49a85cf
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/uciengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "uciengine.h"

#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QStringList>
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 49a85cf

Please sign in to comment.