cbsref/csyrefplugins/csy27010/src/CsyDebugLogger.cpp
branchRCL_3
changeset 65 630d2f34d719
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
       
     1 //
       
     2 // * Copyright 2004 Neusoft America Inc.
       
     3 // * All rights reserved.
       
     4 // * This component and the accompanying materials are made available
       
     5 // * under the terms of the Eclipse Public License v1.0
       
     6 // * which accompanies this distribution, and is available
       
     7 // * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // *
       
     9 // * Contributors:
       
    10 // * Keith Collins (Neusoft America Inc.)  original software development and additional code and modifications.
       
    11 // * Thomas Gahagen (Neusoft America Inc.)  additional code and modifications.
       
    12 // * Zhen Yuan (Neusoft America Inc.)  additional code and modifications.
       
    13 // *
       
    14 // * Description:  This file implements the CCsyDebugLogger class.
       
    15 // *               This class provides the functionality to log TSY debug messages to a file.
       
    16 // *               The log file is located at \epoc32\wins\c\logs\etel.
       
    17 //
       
    18 
       
    19 // CsyDebugLogger.cpp
       
    20 /*
       
    21 Copies from RefLog.cpp
       
    22 MAF move back to using RefLog
       
    23 */
       
    24 
       
    25 // MAF we need to move to using RefLog.cpp - because we are duplicating code
       
    26 // fixes to the code that TapRoot have copied from us.
       
    27 
       
    28 #include <e32svr.h>
       
    29 
       
    30 #include "CsyGlobals.h"
       
    31 #include "CsyDebugLogger.h"
       
    32 
       
    33 #ifdef _DEBUG // Only use the following code when in Debug mode
       
    34 
       
    35 _LIT8(KDateFormat, "%02d.%02d:%4d");
       
    36 _LIT8(KTimeFormat, "%02d.%02d:%02d:%06d ");
       
    37 
       
    38 class TNoOverflow : public TDes8Overflow
       
    39 /**
       
    40  * This class is used to avoid panics when logging anything that's too long.
       
    41  */
       
    42 	{
       
    43 public:
       
    44 	virtual void Overflow(TDes8& /*aDes*/)
       
    45 		{
       
    46 		}
       
    47 	};
       
    48 
       
    49 void CCsyDebugLogger::WriteHeader()
       
    50 /**
       
    51  * Write the log header.
       
    52  */	
       
    53 	{
       
    54 	TBuf8<64> buf;
       
    55 	TTime now;
       
    56 	now.UniversalTime();
       
    57 	TDateTime dateTime;
       
    58 	dateTime = now.DateTime();
       
    59 	// TDateTimes Day() and Month() start at 0
       
    60 	buf.Format(KDateFormat, dateTime.Day() + 1, dateTime.Month() + 1,
       
    61 		dateTime.Year());
       
    62 
       
    63 #ifndef __DEBUGSERIALPORT__
       
    64 	// overwrite log file
       
    65 	RFileLogger logger;
       
    66 	TInt ret = logger.Connect();
       
    67 	if (ret == KErrNone)
       
    68 		{
       
    69 		logger.SetDateAndTime(EFalse, EFalse);
       
    70 		logger.CreateLog(KCsyLogDir, KCsyLogFile, EFileLoggingModeOverwrite);
       
    71 		logger.Write(KCsyLogLine);
       
    72 		logger.CloseLog();
       
    73 		logger.Close();
       
    74 		}
       
    75 #endif
       
    76 
       
    77 	CCsyDebugLogger::Write(_L8(" ")); // please leave this separator in
       
    78 	CCsyDebugLogger::WriteFormat(_L8("Date: %S"), &buf);
       
    79 	CCsyDebugLogger::WriteFormat(_L8("CSY 3GPP 27.010 version %d.%02d  (v8.0 build:%d)"),
       
    80 			KCSY_Gsm0710MajorVersionNumber,
       
    81 			KCSY_Gsm0710MinorVersionNumber,
       
    82 			KCSY_Gsm0710BuildVersionNumber);
       
    83 	}
       
    84 
       
    85 void CCsyDebugLogger::Write(const TDesC8& aText)
       
    86 /**
       
    87  * Write an 8-bit descriptor to the log file.
       
    88  * @param aDebugLevel Debug level of log request
       
    89  * @param aText is the text to write to the log file
       
    90  * @return void
       
    91  */	
       
    92 	{
       
    93 	TBuf8<KLogBufferSize> buf;
       
    94 	TTime now;
       
    95 	now.UniversalTime();
       
    96 	TDateTime dateTime;
       
    97 	dateTime = now.DateTime();
       
    98 	buf.Format(KTimeFormat, dateTime.Hour(), dateTime.Minute(), 
       
    99 			   dateTime.Second(), dateTime.MicroSecond());
       
   100 
       
   101 	if (aText.Length() <= (buf.MaxLength() - buf.Length()))
       
   102 		{
       
   103 		buf.Append(aText);
       
   104 		}
       
   105 	else
       
   106 		{
       
   107 		buf.Append(aText.Left(buf.MaxLength() - buf.Length()));
       
   108 		}
       
   109 
       
   110 #ifdef __DEBUGSERIALPORT__
       
   111 
       
   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 
       
   122 	RDebug::Print(buf2);
       
   123 
       
   124 #else
       
   125 	// log to our own file
       
   126 	RFileLogger logger;
       
   127 	TInt ret = logger.Connect();
       
   128 	if (ret == KErrNone)
       
   129 		{
       
   130 		logger.SetDateAndTime(EFalse, EFalse);
       
   131 		logger.CreateLog(KCsyLogDir, KCsyLogFile, EFileLoggingModeAppend);
       
   132 		logger.Write(buf);
       
   133 		logger.CloseLog();
       
   134 		logger.Close();
       
   135 		}
       
   136 #endif
       
   137 	}
       
   138 
       
   139 void CCsyDebugLogger::WriteFormat(TRefByValue<const TDesC8> aFmt, ...)
       
   140 /**
       
   141  * Write an 8-bit format list to the log file.
       
   142  * @param aDebugLevel Debug level of log request
       
   143  * @param aFmt is the variable arguments
       
   144  * @return void
       
   145  */	
       
   146 	{
       
   147 	VA_LIST list;
       
   148 	VA_START(list,aFmt);
       
   149 
       
   150 	TBuf8<KLogBufferSize> buf;
       
   151 	TNoOverflow overflow;
       
   152 	buf.AppendFormatList(aFmt, list, &overflow);
       
   153 	Write(buf);
       
   154 	}
       
   155 
       
   156 #endif // _DEBUG