Akonadi

filetracer.cpp
1 /***************************************************************************
2  * Copyright (C) 2006 by Tobias Koenig <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as *
6  * published by the Free Software Foundation; either version 2 of the *
7  * License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public *
15  * License along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 #include "filetracer.h"
20 
21 #include <QFile>
22 #include <QTime>
23 
24 using namespace Akonadi::Server;
25 
26 FileTracer::FileTracer(const QString &fileName)
27  : m_file(fileName)
28 {
29  m_file.open(QIODevice::WriteOnly | QIODevice::Unbuffered);
30 }
31 
32 FileTracer::~FileTracer() = default;
33 
34 void FileTracer::beginConnection(const QString &identifier, const QString &msg)
35 {
36  output(identifier, QStringLiteral("begin_connection: %1").arg(msg));
37 }
38 
39 void FileTracer::endConnection(const QString &identifier, const QString &msg)
40 {
41  output(identifier, QStringLiteral("end_connection: %1").arg(msg));
42 }
43 
44 void FileTracer::connectionInput(const QString &identifier, const QByteArray &msg)
45 {
46  output(identifier, QStringLiteral("input: %1").arg(QString::fromUtf8(msg)));
47 }
48 
49 void FileTracer::connectionOutput(const QString &identifier, const QByteArray &msg)
50 {
51  output(identifier, QStringLiteral("output: %1").arg(QString::fromUtf8(msg)));
52 }
53 
54 void FileTracer::signal(const QString &signalName, const QString &msg)
55 {
56  output(QStringLiteral("signal"), QStringLiteral("<%1> %2").arg(signalName, msg));
57 }
58 
59 void FileTracer::warning(const QString &componentName, const QString &msg)
60 {
61  output(QStringLiteral("warning"), QStringLiteral("<%1> %2").arg(componentName, msg));
62 }
63 
64 void FileTracer::error(const QString &componentName, const QString &msg)
65 {
66  output(QStringLiteral("error"), QStringLiteral("<%1> %2").arg(componentName, msg));
67 }
68 
69 void FileTracer::output(const QString &id, const QString &msg)
70 {
71  QString output = QStringLiteral("%1: %2: %3\r\n").arg(QTime::currentTime().toString(QStringLiteral("HH:mm:ss.zzz")), id, msg.left(msg.indexOf(QLatin1Char('\n'))));
72  m_file.write(output.toUtf8());
73 }
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QString fromUtf8(const char *str, int size)
QTime currentTime()
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString left(int n) const const
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.