#include "log.h" #include #include #include #include #include class DebugStream: public QIODevice { public: QString m_location; DebugStream() : QIODevice() { open(WriteOnly); } virtual ~DebugStream(){}; bool isSequential() const { return true; } qint64 readData(char *, qint64) { return 0; /* eof */ } qint64 readLineData(char *, qint64) { return 0; /* eof */ } qint64 writeData(const char *data, qint64 len) { const QByteArray buf = QByteArray::fromRawData(data, len); // if (!qgetenv("IMAP_TRACE").isEmpty()) { // qt_message_output(QtDebugMsg, buf.trimmed().constData()); std::cout << buf.trimmed().constData() << std::endl; // } return len; } private: Q_DISABLE_COPY(DebugStream) }; QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function) { static DebugStream stream; QDebug debug(&stream); static QByteArray programName; if (programName.isEmpty()) { if (QCoreApplication::instance()) programName = QCoreApplication::instance()->applicationName().toLocal8Bit(); else programName = ""; } QString prefix; switch (debugLevel) { case DebugLevel::Trace: prefix = "Trace:"; break; case DebugLevel::Log: prefix = "Log:"; break; case DebugLevel::Warning: prefix = "Warning:"; break; case DebugLevel::Error: prefix = "Error:"; break; default: break; }; debug << prefix + QString(" %1(%2) %3:").arg(QString::fromLatin1(programName)).arg(unsigned(getpid())).arg(function) /* << file << ":" << line */; return debug; }