Mercurial > hg > svcore
comparison base/Debug.cpp @ 951:4b9fc70a37d5
Debug output stuff
author | Chris Cannam |
---|---|
date | Fri, 25 Jul 2014 17:02:44 +0100 |
parents | 387fa69f4eaa |
children | d002827b5896 |
comparison
equal
deleted
inserted
replaced
950:387fa69f4eaa | 951:4b9fc70a37d5 |
---|---|
28 | 28 |
29 #include <cstdio> | 29 #include <cstdio> |
30 | 30 |
31 static QThreadStorage<QDebug *> debugs; | 31 static QThreadStorage<QDebug *> debugs; |
32 static QMutex mutex; | 32 static QMutex mutex; |
33 static QFile *logFile = 0; | |
34 static char *prefix = 0; | 33 static char *prefix = 0; |
35 | 34 |
36 QDebug & | 35 QDebug & |
37 getSVDebug() | 36 getSVDebug() |
38 { | 37 { |
39 mutex.lock(); | 38 mutex.lock(); |
40 | 39 |
41 QDebug *debug = 0; | 40 QDebug *debug = 0; |
42 | 41 |
42 QString pfx = ResourceFinder().getUserResourcePrefix(); | |
43 QDir logdir(QString("%1/%2").arg(pfx).arg("log")); | |
44 | |
43 if (!prefix) { | 45 if (!prefix) { |
44 prefix = new char[20]; | 46 prefix = new char[20]; |
45 sprintf(prefix, "[%lu]", (unsigned long)QCoreApplication::applicationPid()); | 47 sprintf(prefix, "[%lu]", (unsigned long)QCoreApplication::applicationPid()); |
46 QString pfx = ResourceFinder().getUserResourcePrefix(); | |
47 QDir logdir(QString("%1/%2").arg(pfx).arg("log")); | |
48 if (!logdir.exists()) logdir.mkpath(logdir.path()); | 48 if (!logdir.exists()) logdir.mkpath(logdir.path()); |
49 logFile = new QFile(logdir.path() + "/sv-debug.log"); | 49 } |
50 if (logFile->open(QIODevice::WriteOnly | QIODevice::Truncate)) { | 50 |
51 if (!debugs.hasLocalData()) { | |
52 QFile *logFile = new QFile(logdir.path() + "/sv-debug.log"); | |
53 if (logFile->open(QIODevice::WriteOnly | QIODevice::Append)) { | |
51 QDebug(QtDebugMsg) << (const char *)prefix | 54 QDebug(QtDebugMsg) << (const char *)prefix |
52 << "Opened debug log file " | 55 << "Opened debug log file " |
53 << logFile->fileName(); | 56 << logFile->fileName(); |
57 debug = new QDebug(logFile); | |
54 } else { | 58 } else { |
55 QDebug(QtWarningMsg) << (const char *)prefix | 59 QDebug(QtWarningMsg) << (const char *)prefix |
56 << "Failed to open debug log file " | 60 << "Failed to open debug log file " |
57 << logFile->fileName() | 61 << logFile->fileName() |
58 << " for writing, using console debug instead"; | 62 << " for writing, using console debug instead"; |
59 delete logFile; | 63 delete logFile; |
60 logFile = 0; | 64 logFile = 0; |
61 } | |
62 } | |
63 | |
64 if (debugs.hasLocalData()) { | |
65 debug = debugs.localData(); | |
66 } else { | |
67 if (logFile) { | |
68 debug = new QDebug(logFile); | |
69 } else { | |
70 debug = new QDebug(QtDebugMsg); | 65 debug = new QDebug(QtDebugMsg); |
71 } | 66 } |
72 debugs.setLocalData(debug); | 67 debugs.setLocalData(debug); |
73 *debug << endl << (const char *)prefix << "Log started at " | 68 *debug << endl << (const char *)prefix << "Log started at " |
74 << QDateTime::currentDateTime().toString(); | 69 << QDateTime::currentDateTime().toString(); |
70 } else { | |
71 debug = debugs.localData(); | |
75 } | 72 } |
76 | 73 |
77 mutex.unlock(); | 74 mutex.unlock(); |
78 | 75 |
79 QDebug &dref = *debug; | 76 QDebug &dref = *debug; |