KIMAP2

sessionlogger.cpp
1/*
2 Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3 Author: Kevin Ottens <kevin@kdab.com>
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
31using namespace KIMAP2;
32
33SessionLogger::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
52SessionLogger::~SessionLogger()
53{
54 m_file.close();
55}
56
57void SessionLogger::dataSent(const QByteArray &data)
58{
59 m_file.write("C: " + data.trimmed() + '\n');
60 m_file.flush();
61}
62
63void SessionLogger::dataReceived(const QByteArray &data)
64{
65 m_file.write("S: " + data.trimmed() + '\n');
66 m_file.flush();
67}
68
69void SessionLogger::disconnectionOccured()
70{
71 m_file.write("X\n");
72}
QByteArray trimmed() const const
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:18 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.