|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Declares logging macros and CUPLogger class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CUPLOGGER_H |
|
20 #define CUPLOGGER_H |
|
21 |
|
22 #include "logdef.h" |
|
23 |
|
24 /** |
|
25 * NOTE: Link to flogger.lib in MMP file. Use DEBUGLIBRARY -keyword to avoid |
|
26 * warnings in release builds. |
|
27 * Example: DEBUGLIBRARY flogger.lib |
|
28 */ |
|
29 |
|
30 /** |
|
31 * Usage: LOG("[MODULE_NAME]\t Trace text here"); |
|
32 * |
|
33 * Trace target can be changed below (file logging needs directory c:\logs\upnp) |
|
34 * #define __FLOGGING -row uncommented (default) = File logging |
|
35 * #define __CLOGGING -row uncommented = Console logging |
|
36 */ |
|
37 |
|
38 #ifdef ENABLE_LOGGING |
|
39 // Define one of these flags: |
|
40 // FLOGGING = File logging |
|
41 // CLOGGING = Console logging |
|
42 #define __FLOGGING__ |
|
43 //#define __CLOGGING__ |
|
44 #endif |
|
45 |
|
46 |
|
47 |
|
48 // Then actual definitions depending on the |
|
49 // flag values. |
|
50 |
|
51 #ifdef ENABLE_LOGGING |
|
52 |
|
53 #include <e32std.h> |
|
54 #include <f32file.h> |
|
55 |
|
56 |
|
57 // Actual log file name |
|
58 _LIT(KLogFile,"UALog.txt"); |
|
59 |
|
60 // Subdirectory under c:\logs -directory -- MUST EXIST. |
|
61 _LIT(KLogDir, "upnp"); |
|
62 |
|
63 /// The format in which the time is formatted in log |
|
64 _LIT( KLogTimeFormat, "%02d.%02d:%02d:%06d "); |
|
65 _LIT8( KLogTimeFormat8, "%02d.%02d:%02d:%06d "); |
|
66 |
|
67 /// The length of the string produced by KLogTimeFormat |
|
68 const TInt KLogTimeFormatLength = 16; |
|
69 |
|
70 /// How many characters a log line can contain |
|
71 const TInt KLogLineLength = 256; |
|
72 |
|
73 |
|
74 #include <f32file.h> |
|
75 #include <flogger.h> |
|
76 |
|
77 |
|
78 // Define the top level macros |
|
79 #define LOGS(a1, a2) {\ |
|
80 TBuf<1000> log;\ |
|
81 log.Append(_L(a1));\ |
|
82 log.Append(a2);\ |
|
83 Print(log );} |
|
84 #define LOG8S(a1, a2) {\ |
|
85 TBuf8<1000> log;\ |
|
86 log.Append(_L8(a1));\ |
|
87 log.Append(a2);\ |
|
88 Print8(log );} |
|
89 |
|
90 #define LOG(a) {Print( _L(a) ) ;} |
|
91 #define LOG1(s, v) {Print( _L(s), v );} |
|
92 #define LOG2(s, v1, v2) {Print( _L(s), v1, v2 );} |
|
93 |
|
94 #define LOG8(a) {Print8( _L(a) );} |
|
95 #define LOG81(s, v) {Print8( _L8(s), v );} |
|
96 #define LOG82(s, v1, v2) {Print8( _L8(s), v1, v2 );} |
|
97 |
|
98 #ifdef __FLOGGING__ |
|
99 |
|
100 inline void Print( TRefByValue<const TDesC> aText, ... ) |
|
101 { |
|
102 VA_LIST args; |
|
103 VA_START( args, aText ); |
|
104 |
|
105 TBuf<256> buf; |
|
106 buf.FormatList( aText, args ); |
|
107 |
|
108 RFileLogger logger; |
|
109 TInt ret = logger.Connect(); |
|
110 if (ret==KErrNone) |
|
111 { |
|
112 logger.SetDateAndTime( EFalse,EFalse ); |
|
113 logger.CreateLog( KLogDir, KLogFile, EFileLoggingModeAppend ); |
|
114 TBuf<KLogTimeFormatLength> timeStamp; |
|
115 TTime now; |
|
116 now.HomeTime(); |
|
117 TDateTime dateTime; |
|
118 dateTime = now.DateTime(); |
|
119 timeStamp.Format( KLogTimeFormat, |
|
120 dateTime.Hour(), dateTime.Minute(), |
|
121 dateTime.Second(), dateTime.MicroSecond() ); |
|
122 buf.Insert( 0, timeStamp ); |
|
123 |
|
124 logger.Write(buf); |
|
125 } |
|
126 |
|
127 logger.Close(); |
|
128 VA_END( args ); |
|
129 } |
|
130 |
|
131 inline void Print8( TRefByValue<const TDesC8> aText, ... ) |
|
132 { |
|
133 VA_LIST args; |
|
134 VA_START( args, aText ); |
|
135 |
|
136 TBuf8<256> buf; |
|
137 buf.FormatList( aText, args ); |
|
138 |
|
139 RFileLogger logger; |
|
140 TInt ret = logger.Connect(); |
|
141 if (ret==KErrNone) |
|
142 { |
|
143 logger.SetDateAndTime( EFalse,EFalse ); |
|
144 logger.CreateLog( KLogDir, KLogFile, EFileLoggingModeAppend ); |
|
145 TBuf8<KLogTimeFormatLength> timeStamp; |
|
146 TTime now; |
|
147 now.HomeTime(); |
|
148 TDateTime dateTime; |
|
149 dateTime = now.DateTime(); |
|
150 timeStamp.Format( KLogTimeFormat8, |
|
151 dateTime.Hour(), dateTime.Minute(), |
|
152 dateTime.Second(), dateTime.MicroSecond() ); |
|
153 buf.Insert( 0, timeStamp ); |
|
154 |
|
155 logger.Write(buf); |
|
156 } |
|
157 |
|
158 logger.Close(); |
|
159 VA_END( args ); |
|
160 } |
|
161 |
|
162 #else |
|
163 // Console Logging on |
|
164 #define Print RDebug::Print |
|
165 |
|
166 #define LOGS(a1, a2) {\ |
|
167 TBuf<1000> log;\ |
|
168 log.Append(_L(a1));\ |
|
169 log.Append(a2);\ |
|
170 Print(log );} |
|
171 |
|
172 #define LOG8S(a1, a2) {\ |
|
173 TBuf8<1000> log;\ |
|
174 log.Append(_L8(a1));\ |
|
175 log.Append(a2);\ |
|
176 Print(log );} |
|
177 #endif // __FLOGGING__ |
|
178 |
|
179 #else |
|
180 |
|
181 // DEBUG build is not on --> no logging at all |
|
182 #define LOG(a) |
|
183 #define LOG8S(a1, a2) |
|
184 |
|
185 #define LOG1(s, v) |
|
186 #define LOG2(s, v1, v2) |
|
187 |
|
188 #define LOG8(a) |
|
189 #define LOG81(s, v) |
|
190 #define LOG82(s, v1, v2) |
|
191 |
|
192 #endif // ENABLE_LOGGING |
|
193 |
|
194 #endif // CUPLOGGER_H |
|
195 |
|
196 // End of File |