KIMAP2

sessionlogger.cpp
1 /*
2  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3  Author: Kevin Ottens <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "sessionlogger_p.h"
22 
23 #include "kimap_debug.h"
24 
25 #ifdef WIN32
26 #include <process.h>
27 #else
28 #include <unistd.h> //for getpid()
29 #endif
30 
31 using namespace KIMAP2;
32 
33 SessionLogger::SessionLogger()
34  : m_id(0)
35 {
36  static qint64 nextId = 0;
37  m_id = ++nextId;
38 
39  m_file.setFileName(QLatin1String(qgetenv("KIMAP2_LOGFILE"))
40  + QLatin1Char('.')
41 #ifdef WIN32
42  + QString::number(_getpid())
43 #else
44  + QString::number(getpid())
45 #endif
46  + QLatin1Char('.') + QString::number(m_id));
47  if (!m_file.open(QFile::WriteOnly)) {
48  qCDebug(KIMAP2_LOG) << " m_file can be open in write only";
49  }
50 }
51 
52 SessionLogger::~SessionLogger()
53 {
54  m_file.close();
55 }
56 
57 void SessionLogger::dataSent(const QByteArray &data)
58 {
59  m_file.write("C: " + data.trimmed() + '\n');
60  m_file.flush();
61 }
62 
63 void SessionLogger::dataReceived(const QByteArray &data)
64 {
65  m_file.write("S: " + data.trimmed() + '\n');
66  m_file.flush();
67 }
68 
69 void SessionLogger::disconnectionOccured()
70 {
71  m_file.write("X\n");
72 }
QString number(int n, int base)
QByteArray trimmed() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 6 2023 04:10:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.