Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include <f32file.h> // for TParse, in Flogger stuff
21 #include "InuLogger.h"
23 #define KLogsDir _L("c:\\logs\\")
24 #define KInuLogsDirName _L("InetUtils")
25 #define KTestHeader _L("Inet Utils Log")
26 #define KTestCommentPrepend _L("\t")
28 const TInt KMaxLogLineLength = 128;
31 TInuLogger::~TInuLogger()
40 void TInuLogger::CreateFlogger(const TDesC& aFileName, TInt aShowDate, TInt aShowTime)
42 // Create log file in directory KLogsdir\KWapLogsDirName - Note: ingore Drive and Path of aFilename
46 p.Set(aFileName, NULL, NULL);
47 iLogger.CreateLog(KInuLogsDirName, p.NameAndExt(), EFileLoggingModeOverwrite);
48 iLogger.SetDateAndTime(aShowDate, aShowTime);
49 iLogger.Write(KTestHeader);
51 #else if !defined (_DEBUG)
52 void TInuLogger::CreateFlogger(const TDesC& , TInt , TInt ) {}
57 void TInuLogger::LogIt(TRefByValue<const TDesC> aFmt, ...)
59 // Messages to the front end emulator and to the log file
64 TBuf<KMaxFileName> buf;
65 buf.Append(KTestCommentPrepend);
66 buf.AppendFormatList(aFmt,list);
71 #else if !defined (_DEBUG)
72 void TInuLogger::LogIt(TRefByValue<const TDesC> , ...) {}
78 EXPORT_C void TInuLogger::WriteComment(const TDesC& aComment)
80 // Writes aComment to test log file, logging file and test harness
85 while (line.Length() > KMaxLogLineLength)
87 iLogger.Write(line.Left(KMaxLogLineLength));
88 line.Set(line.Right(line.Length() - KMaxLogLineLength));
91 iLogger.Write(line.Left(line.Length()));
95 #else if !defined (_DEBUG)
96 EXPORT_C void TInuLogger::WriteComment(const TDesC& ) {}
103 void TInuLogger::DumpIt(const TDesC8& aData)
104 //Do a formatted dump of binary data
106 // Iterate the supplied block of data in blocks of cols=80 bytes
109 TBuf<KMaxLogLineLength> logLine;
110 TBuf<KMaxLogLineLength> anEntry;
111 while (pos < aData.Length())
113 //start-line exadecimal( a 4 digit number)
114 anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
115 logLine.Append(anEntry.Left(KMaxLogLineLength));
119 for (offset = 0; offset < cols; offset++)
121 if (pos + offset < aData.Length())
123 TInt nextByte = aData[pos + offset];
124 anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
125 logLine.Append(anEntry);
129 //fill the remaining spaces with blanks untill the cols-th Hex number
130 anEntry.Format(TRefByValue<const TDesC>_L(" "));
131 logLine.Append(anEntry);
134 anEntry.Format(TRefByValue<const TDesC>_L(": "));
135 logLine.Append(anEntry);
138 for (offset = 0; offset < cols; offset++)
140 if (pos + offset < aData.Length())
142 TInt nextByte = aData[pos + offset];
143 if ((nextByte >= 32) && (nextByte <= 127))
145 anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
146 logLine.Append(anEntry);
150 anEntry.Format(TRefByValue<const TDesC>_L("."));
151 logLine.Append(anEntry);
156 anEntry.Format(TRefByValue<const TDesC>_L(" "));
157 logLine.Append(anEntry);
160 LogIt(TRefByValue<const TDesC>_L("%S\n"), &logLine);
163 // Advance to next byte segment (1 seg= cols)
167 #else if !defined (_DEBUG)
168 void TInuLogger::DumpIt(const TDesC8& ) {}
173 void TInuLogger::WriteComment(const TDesC8& aData)
174 //Do a write of the supplied data, literally where possible
178 while (line.Length() > KMaxLogLineLength)
180 iLogger.Write(line.Left(KMaxLogLineLength));
181 line.Set(line.Right(line.Length() - KMaxLogLineLength));
184 iLogger.Write(line.Left(line.Length()));
186 #else if !defined (_DEBUG)
187 void TInuLogger::WriteComment(const TDesC8& ) {}