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 <KDebug> |
24 | |
25 | #include <unistd.h> |
26 | |
27 | using namespace KIMAP; |
28 | |
29 | SessionLogger::SessionLogger() |
30 | : m_id( 0 ) |
31 | { |
32 | static qint64 nextId = 0; |
33 | m_id = ++nextId; |
34 | |
35 | m_file.setFileName( QLatin1String(qgetenv( "KIMAP_LOGFILE" )) |
36 | + QLatin1Char('.') + QString::number( getpid() ) |
37 | + QLatin1Char('.') + QString::number( m_id ) ); |
38 | if (!m_file.open( QFile::WriteOnly )) { |
39 | kDebug()<<" m_file can be open in write only" ; |
40 | } |
41 | } |
42 | |
43 | SessionLogger::~SessionLogger() |
44 | { |
45 | m_file.close(); |
46 | } |
47 | |
48 | void SessionLogger::dataSent( const QByteArray &data ) |
49 | { |
50 | m_file.write( "C: " +data.trimmed()+'\n' ); |
51 | m_file.flush(); |
52 | } |
53 | |
54 | void SessionLogger::dataReceived( const QByteArray &data ) |
55 | { |
56 | m_file.write( "S: " +data.trimmed()+'\n' ); |
57 | m_file.flush(); |
58 | } |
59 | |
60 | void SessionLogger::disconnectionOccured() |
61 | { |
62 | m_file.write( "X\n" ); |
63 | } |
64 | |