File indexing completed on 2025-01-05 04:47:02
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org> * 0003 * * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later * 0005 ***************************************************************************/ 0006 #include "filetracer.h" 0007 0008 #include <QTime> 0009 0010 using namespace Akonadi::Server; 0011 0012 FileTracer::FileTracer(const QString &fileName) 0013 : m_file(fileName) 0014 { 0015 m_file.open(QIODevice::WriteOnly | QIODevice::Unbuffered); 0016 } 0017 0018 FileTracer::~FileTracer() = default; 0019 0020 void FileTracer::beginConnection(const QString &identifier, const QString &msg) 0021 { 0022 output(identifier, QStringLiteral("begin_connection: %1").arg(msg)); 0023 } 0024 0025 void FileTracer::endConnection(const QString &identifier, const QString &msg) 0026 { 0027 output(identifier, QStringLiteral("end_connection: %1").arg(msg)); 0028 } 0029 0030 void FileTracer::connectionInput(const QString &identifier, const QByteArray &msg) 0031 { 0032 output(identifier, QStringLiteral("input: %1").arg(QString::fromUtf8(msg))); 0033 } 0034 0035 void FileTracer::connectionOutput(const QString &identifier, const QByteArray &msg) 0036 { 0037 output(identifier, QStringLiteral("output: %1").arg(QString::fromUtf8(msg))); 0038 } 0039 0040 void FileTracer::signal(const QString &signalName, const QString &msg) 0041 { 0042 output(QStringLiteral("signal"), QStringLiteral("<%1> %2").arg(signalName, msg)); 0043 } 0044 0045 void FileTracer::warning(const QString &componentName, const QString &msg) 0046 { 0047 output(QStringLiteral("warning"), QStringLiteral("<%1> %2").arg(componentName, msg)); 0048 } 0049 0050 void FileTracer::error(const QString &componentName, const QString &msg) 0051 { 0052 output(QStringLiteral("error"), QStringLiteral("<%1> %2").arg(componentName, msg)); 0053 } 0054 0055 void FileTracer::output(const QString &id, const QString &msg) 0056 { 0057 QString output = 0058 QStringLiteral("%1: %2: %3\r\n").arg(QTime::currentTime().toString(QStringLiteral("HH:mm:ss.zzz")), id, msg.left(msg.indexOf(QLatin1Char('\n')))); 0059 m_file.write(output.toUtf8()); 0060 }