|
1 /* |
|
2 * Copyright (c) 2009 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 #ifndef __LOGGERUTIL_H |
|
19 #define __LOGGERUTIL_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <QDebug> |
|
23 #include <QFile> |
|
24 #include <QDateTime> |
|
25 |
|
26 /*************************** |
|
27 * LOGGER SETTINGS |
|
28 ***************************/ |
|
29 |
|
30 #ifndef _DEBUG |
|
31 |
|
32 /** |
|
33 * Logging method setting: |
|
34 * 0 = No logging |
|
35 * 1 = File logging, see additional comments later in this file! |
|
36 * 2 = Debug output |
|
37 */ |
|
38 #define _LOGGERUTIL_LOGGING_METHOD 0 // UREL BUILD |
|
39 |
|
40 #else |
|
41 #ifdef __WINS__ |
|
42 #define _LOGGERUTIL_LOGGING_METHOD 2 // UDEB BUILD, WINS |
|
43 #else |
|
44 #define _LOGGERUTIL_LOGGING_METHOD 1 // UDEB BUILD, HW |
|
45 #endif // __WINS__ |
|
46 #endif // _DEBUG |
|
47 |
|
48 // Update this prefix for your component-specific string |
|
49 #define KDBGLOGPRE "VMBXUI: " |
|
50 |
|
51 #if _LOGGERUTIL_LOGGING_METHOD == 1 |
|
52 #define KLOGGERUTILNEWLINE "\n" |
|
53 // Log file location, file created if path exists |
|
54 const QString KLOGGERUTILLOGFILE("c:\\logs\\vmbx\\vmbxui.txt"); |
|
55 #elif _LOGGERUTIL_LOGGING_METHOD == 2 |
|
56 #endif //_LOGGERUTIL_LOGGING_METHOD |
|
57 |
|
58 /*************************** |
|
59 * FILE LOGGING IMPLEMENTATION |
|
60 ***************************/ |
|
61 #if _LOGGERUTIL_LOGGING_METHOD == 1 |
|
62 class DbgLoggerUtil |
|
63 { |
|
64 public: |
|
65 |
|
66 // Constructor opens a file and prints newline+timestamp |
|
67 // |
|
68 // NOTICE the file is not closed if only constructor is run, |
|
69 // other method(s) close the file later explicitly. |
|
70 // |
|
71 // NOTICE that file logging mode uses "append" so the file will grow |
|
72 // indefinitely unless manually deleted. Reason for this is that each |
|
73 // trace line opens&closes the file separately, so overwriting "truncate" |
|
74 // mode would result in the file containing only the latest trace line |
|
75 // and nothing more. |
|
76 DbgLoggerUtil() : mFile( KLOGGERUTILLOGFILE ), mDbg( &mFile ) |
|
77 { |
|
78 if ( mFile.open(QFile::WriteOnly | QFile::Append/*Truncate*/) ) |
|
79 { |
|
80 mDbg << KLOGGERUTILNEWLINE << KDBGLOGPRE |
|
81 << QTime::currentTime().toString(); |
|
82 } |
|
83 } |
|
84 /* Debugging method, remove from production code. |
|
85 ~DbgLoggerUtil() |
|
86 { |
|
87 qDebug() << "~DbgLoggerUtil()"; |
|
88 } |
|
89 */ |
|
90 // This operator writes the argument to file. |
|
91 template<typename T> |
|
92 DbgLoggerUtil &operator << (const T &aParam1) |
|
93 { |
|
94 // File may be already open so check first |
|
95 if ( QIODevice::NotOpen == mFile.openMode() ) |
|
96 { |
|
97 /* result = */ mFile.open( |
|
98 QFile::WriteOnly | QFile::Append/*Truncate*/); |
|
99 } |
|
100 if ( QIODevice::NotOpen != mFile.openMode() ) |
|
101 { |
|
102 mDbg << aParam1; |
|
103 } |
|
104 // In order to optimize the file is left open. |
|
105 // Close it after logging args is finished. |
|
106 return *this; |
|
107 } |
|
108 |
|
109 // This closes the file, dummy parameter not used. |
|
110 template<typename T> |
|
111 DbgLoggerUtil& operator ^ (const T &/*aParam1*/) |
|
112 { |
|
113 mFile.close(); // Also flushes the write buffer |
|
114 return *this; |
|
115 } |
|
116 |
|
117 private: |
|
118 Q_DISABLE_COPY(DbgLoggerUtil) |
|
119 QFile mFile; |
|
120 QDebug mDbg; |
|
121 }; |
|
122 |
|
123 // ^ operator used just for closing the file, 0 is a dummy parameter |
|
124 #define _DBGLOG(AAA) DbgLoggerUtil() << AAA ^ 0; |
|
125 #define _DBGLOG2(AAA,BBB) DbgLoggerUtil() << AAA << BBB ^ 0; |
|
126 #define _DBGLOG3(AAA,BBB,CCC) DbgLoggerUtil() << AAA << BBB << CCC ^ 0; |
|
127 |
|
128 /*************************** |
|
129 * DEBUG PORT LOGGING IMPLEMENTATION |
|
130 ***************************/ |
|
131 #elif _LOGGERUTIL_LOGGING_METHOD == 2 |
|
132 |
|
133 #define _DBGLOG(AAA) qDebug() << KDBGLOGPRE << AAA; |
|
134 #define _DBGLOG2(AAA,BBB) qDebug() << KDBGLOGPRE << AAA << BBB; |
|
135 #define _DBGLOG3(AAA,BBB,CCC) qDebug() << KDBGLOGPRE << AAA << BBB << CCC; |
|
136 |
|
137 #else // _LOGGERUTIL_LOGGING_METHOD == 0 or invalid |
|
138 |
|
139 /*************************** |
|
140 * EMPTY MACROS LOGGING IS DISABLED |
|
141 ***************************/ |
|
142 #define _DBGLOG(AAA) |
|
143 #define _DBGLOG2(AAA,BBB) |
|
144 #define _DBGLOG3(AAA,BBB,CCC) |
|
145 |
|
146 #endif // _LOGGERUTIL_LOGGING_METHOD |
|
147 |
|
148 #endif // __LOGGERUTIL_H |
|
149 // End of File |