mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2025-01-23 08:05:01 +00:00
Detect whether to log to file based upon whether stderr was redirected
This commit is contained in:
parent
e25d9b0da2
commit
aa33432c81
1 changed files with 22 additions and 7 deletions
29
app/main.cpp
29
app/main.cpp
|
@ -44,8 +44,10 @@
|
||||||
#include "settings/streamingpreferences.h"
|
#include "settings/streamingpreferences.h"
|
||||||
#include "gui/sdlgamepadkeynavigation.h"
|
#include "gui/sdlgamepadkeynavigation.h"
|
||||||
|
|
||||||
#if !defined(QT_DEBUG) && defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
// Log to file for release Windows builds
|
#define IS_UNSPECIFIED_HANDLE(x) ((x) == INVALID_HANDLE_VALUE || (x) == NULL)
|
||||||
|
|
||||||
|
// Log to file or console dynamically for Windows builds
|
||||||
#define USE_CUSTOM_LOGGER
|
#define USE_CUSTOM_LOGGER
|
||||||
#define LOG_TO_FILE
|
#define LOG_TO_FILE
|
||||||
#elif defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
|
||||||
|
@ -56,7 +58,7 @@
|
||||||
#define USE_CUSTOM_LOGGER
|
#define USE_CUSTOM_LOGGER
|
||||||
#define LOG_TO_FILE
|
#define LOG_TO_FILE
|
||||||
#else
|
#else
|
||||||
// For debug Windows and Mac builds, use default logger
|
// For debug Mac builds, use default logger
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_CUSTOM_LOGGER
|
#ifdef USE_CUSTOM_LOGGER
|
||||||
|
@ -306,13 +308,26 @@ int main(int argc, char *argv[])
|
||||||
qputenv("QML_DISK_CACHE_PATH", Path::getQmlCacheDir().toUtf8());
|
qputenv("QML_DISK_CACHE_PATH", Path::getQmlCacheDir().toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
// Grab the original std handles before we potentially redirect them later
|
||||||
|
HANDLE oldConOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
HANDLE oldConErr = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_CUSTOM_LOGGER
|
#ifdef USE_CUSTOM_LOGGER
|
||||||
#ifdef LOG_TO_FILE
|
#ifdef LOG_TO_FILE
|
||||||
QDir tempDir(Path::getLogDir());
|
QDir tempDir(Path::getLogDir());
|
||||||
s_LoggerFile = new QFile(tempDir.filePath(QString("Moonlight-%1.log").arg(QDateTime::currentSecsSinceEpoch())));
|
|
||||||
if (s_LoggerFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
|
#ifdef Q_OS_WIN32
|
||||||
QTextStream(stderr) << "Redirecting log output to " << s_LoggerFile->fileName() << Qt::endl;
|
// Only log to a file if the user didn't redirect stderr somewhere else
|
||||||
s_LoggerStream.setDevice(s_LoggerFile);
|
if (IS_UNSPECIFIED_HANDLE(oldConErr))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
s_LoggerFile = new QFile(tempDir.filePath(QString("Moonlight-%1.log").arg(QDateTime::currentSecsSinceEpoch())));
|
||||||
|
if (s_LoggerFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
QTextStream(stderr) << "Redirecting log output to " << s_LoggerFile->fileName() << Qt::endl;
|
||||||
|
s_LoggerStream.setDevice(s_LoggerFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue