|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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 Logger Functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef C_UPNPCUSTOMLOG_H |
|
23 #define C_UPNPCUSTOMLOG_H |
|
24 |
|
25 #include <flogger.h> |
|
26 #include <e32svr.h> |
|
27 |
|
28 // UPNP_LOG : |
|
29 //1 - logging, UDEB |
|
30 //0 - no logging, UREL |
|
31 |
|
32 //UPNP_FLOGGING = file logging, default in UDEB |
|
33 //UPNP_CLOGGING = console logging |
|
34 |
|
35 |
|
36 #ifndef _DEBUG |
|
37 // UREL |
|
38 #define UPNP_LOG 0 // No logging in UREL builds |
|
39 |
|
40 #else |
|
41 |
|
42 // UDEB |
|
43 #define UPNP_LOG 1 |
|
44 #define UPNP_FLOGGING //File logger |
|
45 //#define UPNP_CLOGGING //console logger |
|
46 |
|
47 _LIT(KEventLogFile, "EventActionLog.txt"); |
|
48 // If log file is not defined in CPP file, use UPnPStackLog as default |
|
49 #ifndef KLogFile |
|
50 #define KLogFile _L("UPnPStack.txt") |
|
51 #endif |
|
52 |
|
53 #endif |
|
54 |
|
55 _LIT(KLogFolder,"upnp"); |
|
56 const TInt KMaxLogLen = 256; |
|
57 //_LIT(KLogFile, LOG_FILE); |
|
58 |
|
59 // Writing some descriptor into log |
|
60 // LOGT(own_desc); |
|
61 // |
|
62 // Writing data into log |
|
63 // LOGS("My log string"); |
|
64 // |
|
65 // Writing data with one decimal parameter |
|
66 // LOGS1("Log with decimal parameter %i", desimalValue); |
|
67 // |
|
68 // Writing data with one decimal and hexa parameter |
|
69 // LOGS2("Log with decimal and hexa parameters %i %x", desimalValue, hexaValue); |
|
70 // |
|
71 // Writing data with one descriptor and decimal parameters |
|
72 // LOGS2("String %S and decimal value %i", &stringData, decimalValue); |
|
73 // |
|
74 // Writing User::AllocSize |
|
75 // LOGM; |
|
76 |
|
77 #if UPNP_LOG == 1 |
|
78 |
|
79 #ifdef UPNP_FLOGGING |
|
80 |
|
81 static void DoOutput(TDesC8& aData) |
|
82 { |
|
83 if(!aData.Length()) |
|
84 { |
|
85 return; |
|
86 } |
|
87 RFileLogger logger; |
|
88 logger.Connect(); |
|
89 |
|
90 logger.CreateLog( KLogFolder(), KLogFile, EFileLoggingModeAppend); |
|
91 logger.Write( aData.Mid(0,(aData.Length()<KMaxLogLen)? aData.Length():KMaxLogLen) ); |
|
92 |
|
93 logger.CloseLog(); |
|
94 logger.Close(); |
|
95 } |
|
96 |
|
97 static void DebugStringNarrowL(const char* aFmt, ...) |
|
98 { |
|
99 VA_LIST args; |
|
100 VA_START(args, aFmt); |
|
101 |
|
102 TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt)); |
|
103 |
|
104 HBufC8* buf = HBufC8::NewLC(KMaxLogLen); |
|
105 |
|
106 buf->Des().FormatList(fmt, args); |
|
107 DoOutput(*buf); |
|
108 |
|
109 VA_END(args); |
|
110 CleanupStack::PopAndDestroy(buf); |
|
111 } |
|
112 |
|
113 static void DebugStringWideL(const char* aFmt, ...) |
|
114 { |
|
115 VA_LIST args; |
|
116 VA_START(args, aFmt); |
|
117 |
|
118 TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt)); |
|
119 |
|
120 HBufC* fmt16 = HBufC::NewLC(fmt.Length()); |
|
121 fmt16->Des().Copy(fmt); |
|
122 |
|
123 HBufC* buf = HBufC::NewLC(KMaxLogLen); |
|
124 TPtrC pointer = fmt16->Des() ; |
|
125 buf->Des().FormatList(pointer, args); |
|
126 |
|
127 HBufC8* buf8 = HBufC8::NewLC(buf->Length()); |
|
128 buf8->Des().Copy(*buf); |
|
129 |
|
130 DoOutput(*buf8); |
|
131 |
|
132 VA_END(args); |
|
133 |
|
134 CleanupStack::PopAndDestroy(buf8); |
|
135 CleanupStack::PopAndDestroy(buf); |
|
136 CleanupStack::PopAndDestroy(fmt16); |
|
137 } |
|
138 |
|
139 |
|
140 static void DebugBufferL(const TDesC8& aBuf) |
|
141 { |
|
142 DebugStringNarrowL("\"%S\"", &aBuf); |
|
143 } |
|
144 |
|
145 static void DebugBufferL(const TDesC& aBuf) |
|
146 { |
|
147 DebugStringWideL("\"%S\"", &aBuf); |
|
148 } |
|
149 |
|
150 static void DebugTimeL() |
|
151 { |
|
152 TTime time; |
|
153 time.UniversalTime(); |
|
154 |
|
155 TBuf<64> dateTimeString; |
|
156 |
|
157 _LIT(KTimeString, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B"); |
|
158 time.FormatL(dateTimeString, KTimeString); |
|
159 DebugBufferL(dateTimeString); |
|
160 |
|
161 } |
|
162 |
|
163 |
|
164 // ------------ Content Directory logging specific --------------- |
|
165 _LIT(KInfoFormatString, "INFO#%S#%S#%d#%S"); |
|
166 _LIT(KErrFormatString, "ERROR#%S#%S#%d#%S"); |
|
167 |
|
168 static void LOGCD(const char* aInFunction, const char* aCalledFunction, TInt aErrorCode, const char* aComment) |
|
169 { |
|
170 // Transforming parameters from 'const char *' into 'HBufC' |
|
171 TPtrC8 InFunction8(reinterpret_cast<const unsigned char *>(aInFunction)); |
|
172 HBufC* InFunction16 = HBufC::NewLC(128); |
|
173 InFunction16->Des().Copy(InFunction8); |
|
174 |
|
175 TPtrC8 CalledFunction8(reinterpret_cast<const unsigned char *>(aCalledFunction)); |
|
176 HBufC* CalledFunction16 = HBufC::NewLC(128); |
|
177 CalledFunction16->Des().Copy(CalledFunction8); |
|
178 |
|
179 TPtrC8 Comment8(reinterpret_cast<const unsigned char *>(aComment)); |
|
180 HBufC* Comment16 = HBufC::NewLC(128); |
|
181 Comment16->Des().Copy(Comment8); |
|
182 |
|
183 // preparing main 16bit buffer |
|
184 HBufC* buf = HBufC::NewLC(KMaxLogLen); |
|
185 |
|
186 // formating all together in 16bit descriptor |
|
187 if(aErrorCode < 0) |
|
188 { |
|
189 buf->Des().Format(KErrFormatString, &*InFunction16, &*CalledFunction16, aErrorCode, &*Comment16); |
|
190 } |
|
191 else |
|
192 { |
|
193 buf->Des().Format(KInfoFormatString, &*InFunction16, &*CalledFunction16, aErrorCode, &*Comment16); |
|
194 } |
|
195 |
|
196 // converting 16bit descriptor into 8bit one |
|
197 HBufC8* buf8 = HBufC8::NewLC(buf->Length()); |
|
198 buf8->Des().Copy(*buf); |
|
199 |
|
200 // main file logging |
|
201 DoOutput(*buf8); |
|
202 |
|
203 // cleaning |
|
204 CleanupStack::PopAndDestroy(buf8); |
|
205 CleanupStack::PopAndDestroy(buf); |
|
206 CleanupStack::PopAndDestroy(Comment16); |
|
207 CleanupStack::PopAndDestroy(CalledFunction16); |
|
208 CleanupStack::PopAndDestroy(InFunction16); |
|
209 } |
|
210 |
|
211 |
|
212 #define LOGTIME DebugTimeL() |
|
213 #define LOG(x) DebugStringNarrowL x |
|
214 #define LOG8(x) DebugStringNarrowL x |
|
215 #define LOG16(x) DebugStringWideL x |
|
216 |
|
217 #define LOGT(A) |
|
218 #define LOGS(A) LOG16((A)) |
|
219 #define LOGS1(A,B) LOG16((A,B)) |
|
220 #define LOGS2(A,B,C) LOG16((A,B,C)) |
|
221 #define LOGM |
|
222 |
|
223 #define LOGTH(H,A) LOGT(A) |
|
224 #define LOGSH(H,A) LOGS(A) |
|
225 #define LOGS1H(H,A,B) LOGS1(A,B) |
|
226 #define LOGS2H(H,A,B,C) LOGS2(A,B,C) |
|
227 |
|
228 #define ACTIONSEND(A) |
|
229 #define ACTIONRECV(A,B) |
|
230 |
|
231 static void LOGSQL(const char* aInFunction, const char* aCalledFunction, TInt aErrorCode, const TDesC* aCommand) |
|
232 { |
|
233 LOGCD(aInFunction, aCalledFunction, aErrorCode, "SQL Command:"); |
|
234 |
|
235 // log whole sql command separately |
|
236 LOGS1("%S", aCommand); |
|
237 } |
|
238 |
|
239 |
|
240 |
|
241 #else // UPNP_CLOGGING = console logging |
|
242 #define LOGS(A) RDebug::Print(_L(A)); |
|
243 #define LOGS1(A,B) RDebug::Print(_L(A),B); |
|
244 #define LOGS2(A,B,C) RDebug::Print(_L(A),B,C); |
|
245 |
|
246 #define LOGT(A) |
|
247 #define LOGM |
|
248 #define ACTIONSEND(A) |
|
249 #define ACTIONRECV(A,B) |
|
250 |
|
251 #define LOGTH(H,A) LOGT(A) |
|
252 #define LOGSH(H,A) LOGS(A) |
|
253 #define LOGS1H(H,A,B) LOGS1(A,B) |
|
254 #define LOGS2H(H,A,B,C) LOGS2(A,B,C) |
|
255 #define LOGCD(A,B,C,D) |
|
256 #define LOGSQL(A,B,C,D) |
|
257 |
|
258 #define LOGTIME |
|
259 #define LOG(x) |
|
260 #define LOG8(x) |
|
261 #define LOG16(x) |
|
262 |
|
263 |
|
264 #endif //UPNP_LOG == 1 |
|
265 |
|
266 #else // UPNP_LOG == 0 or invalid |
|
267 #define LOGT(A) |
|
268 #define LOGS(A) |
|
269 #define LOGS1(A,B) |
|
270 #define LOGS2(A,B,C) |
|
271 #define LOGM |
|
272 #define ACTIONSEND(A) |
|
273 #define ACTIONRECV(A,B) |
|
274 |
|
275 #define LOGTH(H,A) |
|
276 #define LOGSH(H,A) |
|
277 #define LOGS1H(H,A,B) |
|
278 #define LOGS2H(H,A,B,C) |
|
279 |
|
280 #define LOGCD(A,B,C,D) |
|
281 #define LOGSQL(A,B,C,D) |
|
282 |
|
283 #define LOGTIME |
|
284 #define LOG(x) |
|
285 #define LOG8(x) |
|
286 #define LOG16(x) |
|
287 |
|
288 #endif // UPNP_LOG |
|
289 |
|
290 #define LOG_FUNC_NAME LOGS( __PRETTY_FUNCTION__ ) |
|
291 |
|
292 #endif // C_UPNPCUSTOMLOG_H |
|
293 |
|
294 // End Of File |