22 #include <QMutexLocker> 25 #include <QCoreApplication> 27 #include <QThreadStorage> 31 static QThreadStorage<QDebug *>
debugs;
43 QDir logdir(QString(
"%1/%2").arg(pfx).arg(
"log"));
47 sprintf(
prefix,
"[%lu]", (
unsigned long)QCoreApplication::applicationPid());
49 if (!logdir.exists()) logdir.mkpath(logdir.path());
52 if (!
debugs.hasLocalData()) {
53 QFile *logFile =
new QFile(logdir.path() +
"/sv-debug.log");
54 if (logFile->open(QIODevice::WriteOnly | QIODevice::Append)) {
55 QDebug(QtDebugMsg) << (
const char *)
prefix 56 <<
"Opened debug log file " 57 << logFile->fileName();
58 debug =
new QDebug(logFile);
60 QDebug(QtWarningMsg) << (
const char *)
prefix 61 <<
"Failed to open debug log file " 62 << logFile->fileName()
63 <<
" for writing, using console debug instead";
66 debug =
new QDebug(QtDebugMsg);
68 debugs.setLocalData(debug);
69 *debug << endl << (
const char *)
prefix <<
"Log started at " 70 << QDateTime::currentDateTime().toString();
72 debug =
debugs.localData();
77 QDebug &dref = *debug;
78 dref << endl << (
const char *)
prefix;
86 dbg << QString::fromUtf8(s.c_str());
93 return target << str.toStdString();
99 return target <<
"<" << u.toString().toStdString() <<
">";
QDebug & operator<<(QDebug &dbg, const std::string &s)
QString getUserResourcePrefix()
Return the root path for user-specific resource installation for this application (i....
static QThreadStorage< QDebug * > debugs