changeset 477:555496d418f1

Place debug log in application data directory (fixes #193)
author Chris Cannam
date Tue, 26 Jul 2011 15:22:54 +0100
parents 7e8688784980
children 1cb27ad6771f
files src/debug.cpp
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/debug.cpp	Tue Jul 26 15:21:45 2011 +0100
+++ b/src/debug.cpp	Tue Jul 26 15:22:54 2011 +0100
@@ -25,6 +25,7 @@
 #include <QDir>
 #include <QCoreApplication>
 #include <QDateTime>
+#include <QDesktopServices>
 
 #include <cstdio>
 
@@ -39,7 +40,15 @@
     if (!debug) {
         prefix = new char[20];
         sprintf(prefix, "[%lu]", (unsigned long)QCoreApplication::applicationPid());
-        logFile = new QFile(QDir::homePath() + "/.easyhg.log");
+        QString logFileName = QDir::homePath() + "/.easyhg.log"; // the fallback
+        QString logDir = QDesktopServices::storageLocation
+            (QDesktopServices::DataLocation);
+        if (logDir != "" &&
+            (QDir(logDir).exists() ||
+             QDir().mkpath(logDir))) {
+            logFileName = logDir + "/debug.log";
+        }
+        logFile = new QFile(logFileName);
         if (logFile->open(QIODevice::WriteOnly | QIODevice::Truncate)) {
             QDebug(QtDebugMsg) << (const char *)prefix
                                << "Opened debug log file "