1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Implements CBttLogger. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "bttlog.h" |
|
23 |
|
24 #ifdef __BTT_LOGGING__ |
|
25 |
|
26 #ifdef __DEBUGRAWIPSERIALPORT__ |
|
27 #include <e32svr.h> |
|
28 #endif |
|
29 |
|
30 //Enable this if you want time stamps for each log statements. |
|
31 //This is computation ineffective and not recommended. |
|
32 //#define __TIME_STAMP_ENABLED__ |
|
33 |
|
34 CBttLogger* CBttLogger::NewL(const TDesC8& aTag, const TDesC8& aFileName, const TUint32 aInstanceId) |
|
35 /** |
|
36 * Factory method for CBttLogger. |
|
37 * |
|
38 * @param aSubDir The subdirectory of c:\logs\gprsbtt to log to. |
|
39 * @param aFileName The filename to log to. |
|
40 * @return Ownership of a new CBttLogger. |
|
41 */ |
|
42 { |
|
43 CBttLogger* self = new(ELeave) CBttLogger; |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(aTag, aFileName, aInstanceId); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 #ifdef __FLOG_ACTIVE |
|
51 void CBttLogger::ConstructL(const TDesC8& aTag, const TDesC8& aFileName, const TUint32 aInstanceId) |
|
52 #else |
|
53 void CBttLogger::ConstructL(const TDesC8&, const TDesC8&, const TUint32 aInstanceId) |
|
54 #endif |
|
55 /** |
|
56 * 2nd-phase construction. |
|
57 * Hurricane/Typhoon - we can log to a particular directory |
|
58 */ |
|
59 { |
|
60 iInstanceId = aInstanceId; |
|
61 __FLOG_OPEN(aTag, aFileName); |
|
62 } |
|
63 |
|
64 //#endif |
|
65 |
|
66 CBttLogger::CBttLogger() |
|
67 /** |
|
68 * Constructor |
|
69 */ |
|
70 { |
|
71 } |
|
72 |
|
73 CBttLogger::~CBttLogger() |
|
74 /** |
|
75 * Destructor |
|
76 */ |
|
77 { |
|
78 __FLOG_CLOSE; |
|
79 } |
|
80 |
|
81 void CBttLogger::Write(const TDesC8& aText) |
|
82 /** |
|
83 * Write an 8-bit descriptor to the log file |
|
84 * |
|
85 * @param aText The test to write |
|
86 */ |
|
87 { |
|
88 TBuf8<KLogBufferSize> buf; |
|
89 TLogIgnoreOverflow8 overflowHandler; |
|
90 // put the instance id to identify which nif we are |
|
91 // logging from |
|
92 _LIT8(KInstanceFormat, "RawIp 0x%08X: "); |
|
93 buf.Format(KInstanceFormat, &overflowHandler, iInstanceId); |
|
94 |
|
95 #ifdef __TIME_STAMP_ENABLED__ |
|
96 // log to our own file in Hurricane/Typhoon |
|
97 _LIT8(KTimeFormat, "%02d.%02d:%02d:%06d "); |
|
98 |
|
99 TTime now; |
|
100 now.UniversalTime(); |
|
101 TDateTime dateTime; |
|
102 dateTime = now.DateTime(); |
|
103 buf.AppendFormat(KTimeFormat, |
|
104 &overflowHandler, |
|
105 dateTime.Hour(), |
|
106 dateTime.Minute(), |
|
107 dateTime.Second(), |
|
108 dateTime.MicroSecond()); |
|
109 #endif |
|
110 |
|
111 buf.Append(aText); |
|
112 |
|
113 #ifdef __DEBUGRAWIPSERIALPORT__ |
|
114 TBuf<KLogBufferSize> buf2; |
|
115 // TEMP: Do not print single % since appear as format char to RDebug::Print |
|
116 for (TInt i = 0; i < buf.Length(); i++) |
|
117 { |
|
118 if (buf[i] == '%') |
|
119 buf2.Append(_L(".")); |
|
120 else |
|
121 buf2.Append(buf[i]); |
|
122 } |
|
123 RDebug::Print(buf2); |
|
124 #else |
|
125 __FLOG(buf); |
|
126 #endif |
|
127 } |
|
128 |
|
129 void CBttLogger::WriteFormat(TRefByValue<const TDesC8> aFmt, ...) |
|
130 /** |
|
131 * Write an 8-bit format list to the log file |
|
132 */ |
|
133 { |
|
134 //coverity[var_decl]; |
|
135 VA_LIST list; |
|
136 VA_START(list, aFmt); |
|
137 |
|
138 // log to our own file in Hurricane/Typhoon |
|
139 TBuf8<KLogBufferSize> buf; |
|
140 TLogIgnoreOverflow8 overflowHandler; |
|
141 //coverity[uninit_use_in_call]; |
|
142 buf.AppendFormatList(aFmt, list, &overflowHandler); |
|
143 Write(buf); |
|
144 } |
|
145 |
|
146 void CBttLogger::VerboseLeaveL(char* aFile, TInt aLine, TInt aReason) |
|
147 /** |
|
148 * Make a verbose leave - write name of file and line number to the log just |
|
149 * before leaving. |
|
150 * |
|
151 * @param aFile The file we're leaving from. |
|
152 * @param aLine The line number we're leaving from. |
|
153 * @param aReason The leave code. |
|
154 */ |
|
155 { |
|
156 // only leave if non-zero value |
|
157 if ( aReason == KErrNone ) |
|
158 { |
|
159 return; |
|
160 } |
|
161 |
|
162 _LIT8(KLeavePrefix, "LEAVE: " ); |
|
163 |
|
164 TPtrC8 fullFileName((const TUint8*)aFile); |
|
165 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
166 |
|
167 TBuf8<256> buf; |
|
168 TLogIgnoreOverflow8 overflowHandler; |
|
169 buf.AppendFormat(_L8("%S aReason=%d [file %S, line %d]"), |
|
170 &overflowHandler, |
|
171 &KLeavePrefix, |
|
172 aReason, |
|
173 &fileName, |
|
174 aLine); |
|
175 Write(buf); |
|
176 |
|
177 __FLOG_CLOSE; |
|
178 |
|
179 // finally |
|
180 User::Leave(aReason); |
|
181 } |
|
182 |
|
183 void CBttLogger::VerbosePanic(char* aFile, |
|
184 TInt aLine, |
|
185 TInt aPanicCode, |
|
186 TText8* aPanicName, |
|
187 const TDesC& aPanicCategory) |
|
188 /** |
|
189 * Make a verbose panic - write name of file and line number to the |
|
190 * log just before panicking. |
|
191 * |
|
192 * @param aFile The file that's panicking. |
|
193 * @param aLine The line number that's panicking. |
|
194 * @param aReason The panic code. |
|
195 * @param aPanicName The text of the panic code. |
|
196 * @param aPanicCategory The panic category. |
|
197 */ |
|
198 { |
|
199 _LIT8(KLeavePrefix, "PANIC: " ); |
|
200 |
|
201 TPtrC8 fullFileName((const TUint8*)aFile); |
|
202 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
203 |
|
204 TBuf8<256> buf; |
|
205 TLogIgnoreOverflow8 overflowHandler; |
|
206 buf.AppendFormat(_L8("%S %d = %s [file %S, line %d]"), |
|
207 &overflowHandler, |
|
208 &KLeavePrefix, |
|
209 aPanicCode, |
|
210 aPanicName, |
|
211 &fileName, |
|
212 aLine); |
|
213 Write(buf); |
|
214 |
|
215 __FLOG_CLOSE; |
|
216 |
|
217 // finally |
|
218 User::Panic(aPanicCategory, aPanicCode); |
|
219 } |
|
220 |
|
221 #endif // __BTT_LOGGING__ |
|