|
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 // put the instance id to identify which nif we are |
|
90 // logging from |
|
91 _LIT8(KInstanceFormat, "RawIp 0x%08X: "); |
|
92 buf.Format(KInstanceFormat, iInstanceId); |
|
93 |
|
94 #ifdef __TIME_STAMP_ENABLED__ |
|
95 // log to our own file in Hurricane/Typhoon |
|
96 _LIT8(KTimeFormat, "%02d.%02d:%02d:%06d "); |
|
97 |
|
98 TTime now; |
|
99 now.UniversalTime(); |
|
100 TDateTime dateTime; |
|
101 dateTime = now.DateTime(); |
|
102 buf.AppendFormat(KTimeFormat, |
|
103 dateTime.Hour(), |
|
104 dateTime.Minute(), |
|
105 dateTime.Second(), |
|
106 dateTime.MicroSecond()); |
|
107 #endif |
|
108 |
|
109 buf.Append(aText); |
|
110 |
|
111 #ifdef __DEBUGRAWIPSERIALPORT__ |
|
112 TBuf<KLogBufferSize> buf2; |
|
113 // TEMP: Do not print single % since appear as format char to RDebug::Print |
|
114 for (TInt i = 0; i < buf.Length(); i++) |
|
115 { |
|
116 if (buf[i] == '%') |
|
117 buf2.Append(_L(".")); |
|
118 else |
|
119 buf2.Append(buf[i]); |
|
120 } |
|
121 RDebug::Print(buf2); |
|
122 #else |
|
123 __FLOG(buf); |
|
124 #endif |
|
125 } |
|
126 |
|
127 void CBttLogger::WriteFormat(TRefByValue<const TDesC8> aFmt, ...) |
|
128 /** |
|
129 * Write an 8-bit format list to the log file |
|
130 */ |
|
131 { |
|
132 VA_LIST list; |
|
133 VA_START(list, aFmt); |
|
134 |
|
135 // log to our own file in Hurricane/Typhoon |
|
136 TBuf8<KLogBufferSize> buf; |
|
137 buf.AppendFormatList(aFmt, list); |
|
138 Write(buf); |
|
139 } |
|
140 |
|
141 void CBttLogger::VerboseLeaveL(char* aFile, TInt aLine, TInt aReason) |
|
142 /** |
|
143 * Make a verbose leave - write name of file and line number to the log just |
|
144 * before leaving. |
|
145 * |
|
146 * @param aFile The file we're leaving from. |
|
147 * @param aLine The line number we're leaving from. |
|
148 * @param aReason The leave code. |
|
149 */ |
|
150 { |
|
151 // only leave if non-zero value |
|
152 if ( aReason == KErrNone ) |
|
153 { |
|
154 return; |
|
155 } |
|
156 |
|
157 _LIT8(KLeavePrefix, "LEAVE: " ); |
|
158 |
|
159 TPtrC8 fullFileName((const TUint8*)aFile); |
|
160 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
161 |
|
162 TBuf8<256> buf; |
|
163 buf.Append(KLeavePrefix); |
|
164 buf.AppendFormat(_L8(" aReason=%d [file %S, line %d]"), aReason, &fileName, |
|
165 aLine); |
|
166 Write(buf); |
|
167 |
|
168 __FLOG_CLOSE; |
|
169 |
|
170 // finally |
|
171 User::Leave(aReason); |
|
172 } |
|
173 |
|
174 void CBttLogger::VerbosePanic(char* aFile, |
|
175 TInt aLine, |
|
176 TInt aPanicCode, |
|
177 TText8* aPanicName, |
|
178 const TDesC& aPanicCategory) |
|
179 /** |
|
180 * Make a verbose panic - write name of file and line number to the |
|
181 * log just before panicking. |
|
182 * |
|
183 * @param aFile The file that's panicking. |
|
184 * @param aLine The line number that's panicking. |
|
185 * @param aReason The panic code. |
|
186 * @param aPanicName The text of the panic code. |
|
187 * @param aPanicCategory The panic category. |
|
188 */ |
|
189 { |
|
190 _LIT8(KLeavePrefix, "PANIC: " ); |
|
191 |
|
192 TPtrC8 fullFileName((const TUint8*)aFile); |
|
193 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
194 |
|
195 TBuf8<256> buf; |
|
196 buf.Append(KLeavePrefix); |
|
197 buf.AppendFormat(_L8(" %d = %s [file %S, line %d]"), |
|
198 aPanicCode, |
|
199 aPanicName, |
|
200 &fileName, |
|
201 aLine); |
|
202 Write(buf); |
|
203 |
|
204 __FLOG_CLOSE; |
|
205 |
|
206 // finally |
|
207 User::Panic(aPanicCategory, aPanicCode); |
|
208 } |
|
209 |
|
210 #endif // __BTT_LOGGING__ |