|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef QSTMFILELOGGER_H_ |
|
20 #define QSTMFILELOGGER_H_ |
|
21 |
|
22 #include <qstmgesturedefs.h> |
|
23 #include <QFile> |
|
24 #include <QDebug> |
|
25 #include <QString> |
|
26 #include <QStringBuilder> |
|
27 |
|
28 #define LOGFLUSH QStm_FileLogger::flush() |
|
29 #define LOGCLOSE QStm_FileLogger::close() |
|
30 #ifdef Q_OS_WIN |
|
31 #define LOGARG() |
|
32 #else |
|
33 #define LOGARG(txt,parm...) {QStm_FileLogger::log(txt, parm);} |
|
34 #endif |
|
35 #define LOGTXT(txt) {QStm_FileLogger::log("%s",txt);} |
|
36 #define LOGERR(txt,err) if (!err) {} else {LOGARG(txt, err);} |
|
37 #define LOGCALL(exp) {LOGARG("Calling \"%s\"", #exp); exp; LOGARG("Call to \"%s\" passed.", #exp);} |
|
38 #define LOGENTER LOGARG("%s start", __PRETTY_FUNCTION__) |
|
39 #define LOGEXIT LOGARG("%s end", __PRETTY_FUNCTION__) |
|
40 #define LOGMEM(ptr) LOGARG("%s [0x%x]", #ptr, (uint)ptr) |
|
41 |
|
42 class QSTMGESTURELIB_EXPORT QStm_FileLogger |
|
43 { |
|
44 public: |
|
45 static void log(const QString& text); |
|
46 static void log(const char* fmt,...); |
|
47 static void close() { logger()->doClose(); } |
|
48 static void flush() { logger()->doFlush(); } |
|
49 static QStm_FileLogger* logger(); |
|
50 static QIODevice* ioDevice() { return logger()->m_file; } |
|
51 private: |
|
52 QStm_FileLogger(); |
|
53 ~QStm_FileLogger(); |
|
54 void doLog(const QString& text); |
|
55 void doLog(const char* text); |
|
56 void doClose() { m_file->close(); } |
|
57 void doFlush() { m_stream->flush(); } |
|
58 QString getLogFileName(); |
|
59 |
|
60 private: |
|
61 QFile* m_file; |
|
62 QTextStream* m_stream; |
|
63 static QStm_FileLogger* m_instance; |
|
64 }; |
|
65 |
|
66 |
|
67 |
|
68 #endif /* QSTMFILELOGGER_H_ */ |