|
1 // Copyright (c) 2001-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 // inulogger.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <f32file.h> // for TParse, in Flogger stuff |
|
19 |
|
20 |
|
21 #include "InuLogger.h" |
|
22 |
|
23 #define KLogsDir _L("c:\\logs\\") |
|
24 #define KInuLogsDirName _L("InetUtils") |
|
25 #define KTestHeader _L("Inet Utils Log") |
|
26 #define KTestCommentPrepend _L("\t") |
|
27 |
|
28 const TInt KMaxLogLineLength = 128; |
|
29 |
|
30 EXPORT_C |
|
31 TInuLogger::~TInuLogger() |
|
32 { |
|
33 #if defined (_DEBUG) |
|
34 iLogger.Close(); |
|
35 #endif |
|
36 } |
|
37 |
|
38 EXPORT_C |
|
39 #if defined (_DEBUG) |
|
40 void TInuLogger::CreateFlogger(const TDesC& aFileName, TInt aShowDate, TInt aShowTime) |
|
41 // |
|
42 // Create log file in directory KLogsdir\KWapLogsDirName - Note: ingore Drive and Path of aFilename |
|
43 { |
|
44 iLogger.Connect(); |
|
45 TParse p; |
|
46 p.Set(aFileName, NULL, NULL); |
|
47 iLogger.CreateLog(KInuLogsDirName, p.NameAndExt(), EFileLoggingModeOverwrite); |
|
48 iLogger.SetDateAndTime(aShowDate, aShowTime); |
|
49 iLogger.Write(KTestHeader); |
|
50 } |
|
51 #else if !defined (_DEBUG) |
|
52 void TInuLogger::CreateFlogger(const TDesC& , TInt , TInt ) {} |
|
53 #endif |
|
54 |
|
55 EXPORT_C |
|
56 #if defined (_DEBUG) |
|
57 void TInuLogger::LogIt(TRefByValue<const TDesC> aFmt, ...) |
|
58 // |
|
59 // Messages to the front end emulator and to the log file |
|
60 { |
|
61 VA_LIST list; |
|
62 VA_START(list,aFmt); |
|
63 |
|
64 TBuf<KMaxFileName> buf; |
|
65 buf.Append(KTestCommentPrepend); |
|
66 buf.AppendFormatList(aFmt,list); |
|
67 VA_END(list); |
|
68 |
|
69 WriteComment(buf); |
|
70 } |
|
71 #else if !defined (_DEBUG) |
|
72 void TInuLogger::LogIt(TRefByValue<const TDesC> , ...) {} |
|
73 #endif |
|
74 |
|
75 |
|
76 |
|
77 #if defined (_DEBUG) |
|
78 EXPORT_C void TInuLogger::WriteComment(const TDesC& aComment) |
|
79 // |
|
80 // Writes aComment to test log file, logging file and test harness |
|
81 { |
|
82 TPtrC line; |
|
83 line.Set(aComment); |
|
84 |
|
85 while (line.Length() > KMaxLogLineLength) |
|
86 { |
|
87 iLogger.Write(line.Left(KMaxLogLineLength)); |
|
88 line.Set(line.Right(line.Length() - KMaxLogLineLength)); |
|
89 } |
|
90 |
|
91 iLogger.Write(line.Left(line.Length())); |
|
92 |
|
93 } |
|
94 |
|
95 #else if !defined (_DEBUG) |
|
96 EXPORT_C void TInuLogger::WriteComment(const TDesC& ) {} |
|
97 #endif |
|
98 |
|
99 |
|
100 |
|
101 EXPORT_C |
|
102 #if defined (_DEBUG) |
|
103 void TInuLogger::DumpIt(const TDesC8& aData) |
|
104 //Do a formatted dump of binary data |
|
105 { |
|
106 // Iterate the supplied block of data in blocks of cols=80 bytes |
|
107 const TInt cols=16; |
|
108 TInt pos = 0; |
|
109 TBuf<KMaxLogLineLength> logLine; |
|
110 TBuf<KMaxLogLineLength> anEntry; |
|
111 while (pos < aData.Length()) |
|
112 { |
|
113 //start-line exadecimal( a 4 digit number) |
|
114 anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos); |
|
115 logLine.Append(anEntry.Left(KMaxLogLineLength)); |
|
116 |
|
117 // Hex output |
|
118 TInt offset; |
|
119 for (offset = 0; offset < cols; offset++) |
|
120 { |
|
121 if (pos + offset < aData.Length()) |
|
122 { |
|
123 TInt nextByte = aData[pos + offset]; |
|
124 anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte); |
|
125 logLine.Append(anEntry); |
|
126 } |
|
127 else |
|
128 { |
|
129 //fill the remaining spaces with blanks untill the cols-th Hex number |
|
130 anEntry.Format(TRefByValue<const TDesC>_L(" ")); |
|
131 logLine.Append(anEntry); |
|
132 } |
|
133 } |
|
134 anEntry.Format(TRefByValue<const TDesC>_L(": ")); |
|
135 logLine.Append(anEntry); |
|
136 |
|
137 // Char output |
|
138 for (offset = 0; offset < cols; offset++) |
|
139 { |
|
140 if (pos + offset < aData.Length()) |
|
141 { |
|
142 TInt nextByte = aData[pos + offset]; |
|
143 if ((nextByte >= 32) && (nextByte <= 127)) |
|
144 { |
|
145 anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte); |
|
146 logLine.Append(anEntry); |
|
147 } |
|
148 else |
|
149 { |
|
150 anEntry.Format(TRefByValue<const TDesC>_L(".")); |
|
151 logLine.Append(anEntry); |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 anEntry.Format(TRefByValue<const TDesC>_L(" ")); |
|
157 logLine.Append(anEntry); |
|
158 } |
|
159 } |
|
160 LogIt(TRefByValue<const TDesC>_L("%S\n"), &logLine); |
|
161 logLine.Zero(); |
|
162 |
|
163 // Advance to next byte segment (1 seg= cols) |
|
164 pos += cols; |
|
165 } |
|
166 } |
|
167 #else if !defined (_DEBUG) |
|
168 void TInuLogger::DumpIt(const TDesC8& ) {} |
|
169 #endif |
|
170 |
|
171 EXPORT_C |
|
172 #if defined (_DEBUG) |
|
173 void TInuLogger::WriteComment(const TDesC8& aData) |
|
174 //Do a write of the supplied data, literally where possible |
|
175 { |
|
176 TPtrC8 line; |
|
177 line.Set(aData); |
|
178 while (line.Length() > KMaxLogLineLength) |
|
179 { |
|
180 iLogger.Write(line.Left(KMaxLogLineLength)); |
|
181 line.Set(line.Right(line.Length() - KMaxLogLineLength)); |
|
182 } |
|
183 |
|
184 iLogger.Write(line.Left(line.Length())); |
|
185 } |
|
186 #else if !defined (_DEBUG) |
|
187 void TInuLogger::WriteComment(const TDesC8& ) {} |
|
188 #endif |
|
189 |