KIMAP

sessionlogger.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3  SPDX-FileContributor: Kevin Ottens <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "sessionlogger_p.h"
9 
10 #include "kimap_debug.h"
11 #include <QCoreApplication>
12 
13 using namespace KIMAP;
14 
15 SessionLogger::SessionLogger()
16 {
17  static qint64 nextId = 0;
18  m_id = ++nextId;
19 
20  m_file.setFileName(QLatin1String(qgetenv("KIMAP_LOGFILE")) + QLatin1Char('.') + QString::number(QCoreApplication::applicationPid()) + QLatin1Char('.')
21  + QString::number(m_id));
22  if (!m_file.open(QFile::WriteOnly)) {
23  qCWarning(KIMAP_LOG) << "Could not open log file for writing:" << m_file.fileName();
24  }
25 }
26 
27 SessionLogger::~SessionLogger()
28 {
29  m_file.close();
30 }
31 
32 void SessionLogger::dataSent(const QByteArray &data)
33 {
34  m_file.write("C: " + data.trimmed() + '\n');
35  m_file.flush();
36 }
37 
38 void SessionLogger::dataReceived(const QByteArray &data)
39 {
40  m_file.write("S: " + data.trimmed() + '\n');
41  m_file.flush();
42 }
43 
44 void SessionLogger::disconnectionOccured()
45 {
46  m_file.write("X\n");
47 }
QString number(int n, int base)
QByteArray trimmed() const const
qint64 applicationPid()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 10 2023 03:48:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.