Chris@57: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@57: Chris@57: /* Chris@57: EasyMercurial Chris@57: Chris@57: Based on HgExplorer by Jari Korhonen Chris@57: Copyright (c) 2010 Jari Korhonen Chris@57: Copyright (c) 2010 Chris Cannam Chris@57: Copyright (c) 2010 Queen Mary, University of London Chris@57: Chris@57: This program is free software; you can redistribute it and/or Chris@57: modify it under the terms of the GNU General Public License as Chris@57: published by the Free Software Foundation; either version 2 of the Chris@57: License, or (at your option) any later version. See the file Chris@57: COPYING included with this distribution for more information. Chris@57: */ Chris@57: Chris@57: #include "debug.h" Chris@57: Chris@57: #include Chris@57: #include Chris@57: #include Chris@57: #include Chris@57: #include Chris@57: #include Chris@57: #include Chris@57: Chris@57: #include Chris@57: Chris@57: QDebug & Chris@57: getEasyHgDebug() Chris@57: { Chris@57: static QFile *logFile = 0; Chris@57: static QDebug *debug = 0; Chris@57: static QMutex mutex; Chris@57: static char *prefix; Chris@57: mutex.lock(); Chris@57: if (!debug) { Chris@57: prefix = new char[20]; Chris@57: sprintf(prefix, "[%lu]", (unsigned long)getpid()); Chris@57: logFile = new QFile(QDir::homePath() + "/.easyhg.log"); Chris@57: if (logFile->open(QIODevice::WriteOnly | QIODevice::Append)) { Chris@57: QDebug(QtDebugMsg) << (const char *)prefix Chris@57: << "Opened debug log file " Chris@57: << logFile->fileName(); Chris@57: debug = new QDebug(logFile); Chris@57: } else { Chris@57: QDebug(QtWarningMsg) << (const char *)prefix Chris@57: << "Failed to open debug log file " Chris@57: << logFile->fileName() Chris@57: << " for writing, using console debug instead"; Chris@57: debug = new QDebug(QtDebugMsg); Chris@57: delete logFile; Chris@57: logFile = 0; Chris@57: } Chris@57: } Chris@57: mutex.unlock(); Chris@57: Chris@57: QDebug &dref = *debug; Chris@57: return dref << endl << (const char *)prefix; Chris@57: } Chris@57: Chris@57: QDebug & Chris@57: operator<<(QDebug &dbg, const std::string &s) Chris@57: { Chris@57: dbg << QString::fromUtf8(s.c_str()); Chris@57: return dbg; Chris@57: } Chris@57: Chris@57: std::ostream & Chris@57: operator<<(std::ostream &target, const QString &str) Chris@57: { Chris@57: return target << str.toLocal8Bit().data(); Chris@57: } Chris@57: Chris@57: std::ostream & Chris@57: operator<<(std::ostream &target, const QUrl &u) Chris@57: { Chris@57: return target << "<" << u.toString() << ">"; Chris@57: } Chris@57: