1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/Test/IpuTestUtils/IpuLogger.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,189 @@
1.4 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// inulogger.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <f32file.h> // for TParse, in Flogger stuff
1.22 +
1.23 +
1.24 +#include "InuLogger.h"
1.25 +
1.26 +#define KLogsDir _L("c:\\logs\\")
1.27 +#define KInuLogsDirName _L("InetUtils")
1.28 +#define KTestHeader _L("Inet Utils Log")
1.29 +#define KTestCommentPrepend _L("\t")
1.30 +
1.31 +const TInt KMaxLogLineLength = 128;
1.32 +
1.33 +EXPORT_C
1.34 +TInuLogger::~TInuLogger()
1.35 + {
1.36 +#if defined (_DEBUG)
1.37 + iLogger.Close();
1.38 +#endif
1.39 + }
1.40 +
1.41 +EXPORT_C
1.42 +#if defined (_DEBUG)
1.43 +void TInuLogger::CreateFlogger(const TDesC& aFileName, TInt aShowDate, TInt aShowTime)
1.44 +//
1.45 +// Create log file in directory KLogsdir\KWapLogsDirName - Note: ingore Drive and Path of aFilename
1.46 + {
1.47 + iLogger.Connect();
1.48 + TParse p;
1.49 + p.Set(aFileName, NULL, NULL);
1.50 + iLogger.CreateLog(KInuLogsDirName, p.NameAndExt(), EFileLoggingModeOverwrite);
1.51 + iLogger.SetDateAndTime(aShowDate, aShowTime);
1.52 + iLogger.Write(KTestHeader);
1.53 + }
1.54 +#else if !defined (_DEBUG)
1.55 +void TInuLogger::CreateFlogger(const TDesC& , TInt , TInt ) {}
1.56 +#endif
1.57 +
1.58 +EXPORT_C
1.59 +#if defined (_DEBUG)
1.60 +void TInuLogger::LogIt(TRefByValue<const TDesC> aFmt, ...)
1.61 +//
1.62 +// Messages to the front end emulator and to the log file
1.63 + {
1.64 + VA_LIST list;
1.65 + VA_START(list,aFmt);
1.66 +
1.67 + TBuf<KMaxFileName> buf;
1.68 + buf.Append(KTestCommentPrepend);
1.69 + buf.AppendFormatList(aFmt,list);
1.70 + VA_END(list);
1.71 +
1.72 + WriteComment(buf);
1.73 + }
1.74 +#else if !defined (_DEBUG)
1.75 +void TInuLogger::LogIt(TRefByValue<const TDesC> , ...) {}
1.76 +#endif
1.77 +
1.78 +
1.79 +
1.80 +#if defined (_DEBUG)
1.81 +EXPORT_C void TInuLogger::WriteComment(const TDesC& aComment)
1.82 +//
1.83 +// Writes aComment to test log file, logging file and test harness
1.84 + {
1.85 + TPtrC line;
1.86 + line.Set(aComment);
1.87 +
1.88 + while (line.Length() > KMaxLogLineLength)
1.89 + {
1.90 + iLogger.Write(line.Left(KMaxLogLineLength));
1.91 + line.Set(line.Right(line.Length() - KMaxLogLineLength));
1.92 + }
1.93 +
1.94 + iLogger.Write(line.Left(line.Length()));
1.95 +
1.96 + }
1.97 +
1.98 +#else if !defined (_DEBUG)
1.99 +EXPORT_C void TInuLogger::WriteComment(const TDesC& ) {}
1.100 +#endif
1.101 +
1.102 +
1.103 +
1.104 +EXPORT_C
1.105 +#if defined (_DEBUG)
1.106 +void TInuLogger::DumpIt(const TDesC8& aData)
1.107 +//Do a formatted dump of binary data
1.108 + {
1.109 + // Iterate the supplied block of data in blocks of cols=80 bytes
1.110 + const TInt cols=16;
1.111 + TInt pos = 0;
1.112 + TBuf<KMaxLogLineLength> logLine;
1.113 + TBuf<KMaxLogLineLength> anEntry;
1.114 + while (pos < aData.Length())
1.115 + {
1.116 + //start-line exadecimal( a 4 digit number)
1.117 + anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
1.118 + logLine.Append(anEntry.Left(KMaxLogLineLength));
1.119 +
1.120 + // Hex output
1.121 + TInt offset;
1.122 + for (offset = 0; offset < cols; offset++)
1.123 + {
1.124 + if (pos + offset < aData.Length())
1.125 + {
1.126 + TInt nextByte = aData[pos + offset];
1.127 + anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
1.128 + logLine.Append(anEntry);
1.129 + }
1.130 + else
1.131 + {
1.132 + //fill the remaining spaces with blanks untill the cols-th Hex number
1.133 + anEntry.Format(TRefByValue<const TDesC>_L(" "));
1.134 + logLine.Append(anEntry);
1.135 + }
1.136 + }
1.137 + anEntry.Format(TRefByValue<const TDesC>_L(": "));
1.138 + logLine.Append(anEntry);
1.139 +
1.140 + // Char output
1.141 + for (offset = 0; offset < cols; offset++)
1.142 + {
1.143 + if (pos + offset < aData.Length())
1.144 + {
1.145 + TInt nextByte = aData[pos + offset];
1.146 + if ((nextByte >= 32) && (nextByte <= 127))
1.147 + {
1.148 + anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
1.149 + logLine.Append(anEntry);
1.150 + }
1.151 + else
1.152 + {
1.153 + anEntry.Format(TRefByValue<const TDesC>_L("."));
1.154 + logLine.Append(anEntry);
1.155 + }
1.156 + }
1.157 + else
1.158 + {
1.159 + anEntry.Format(TRefByValue<const TDesC>_L(" "));
1.160 + logLine.Append(anEntry);
1.161 + }
1.162 + }
1.163 + LogIt(TRefByValue<const TDesC>_L("%S\n"), &logLine);
1.164 + logLine.Zero();
1.165 +
1.166 + // Advance to next byte segment (1 seg= cols)
1.167 + pos += cols;
1.168 + }
1.169 + }
1.170 +#else if !defined (_DEBUG)
1.171 +void TInuLogger::DumpIt(const TDesC8& ) {}
1.172 +#endif
1.173 +
1.174 +EXPORT_C
1.175 +#if defined (_DEBUG)
1.176 +void TInuLogger::WriteComment(const TDesC8& aData)
1.177 +//Do a write of the supplied data, literally where possible
1.178 + {
1.179 + TPtrC8 line;
1.180 + line.Set(aData);
1.181 + while (line.Length() > KMaxLogLineLength)
1.182 + {
1.183 + iLogger.Write(line.Left(KMaxLogLineLength));
1.184 + line.Set(line.Right(line.Length() - KMaxLogLineLength));
1.185 + }
1.186 +
1.187 + iLogger.Write(line.Left(line.Length()));
1.188 + }
1.189 +#else if !defined (_DEBUG)
1.190 +void TInuLogger::WriteComment(const TDesC8& ) {}
1.191 +#endif
1.192 +