telephonyserver/etelsimtoolkit/tetel/TSatLog.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 44 8b72faa1200f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1997-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 // Writes and formats test log information to a log file
       
    15 // Main class is CTestLogger
       
    16 // TSatLog.cpp is based on T_Reslog.cpp & T_Reslog.h
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 
       
    24 #include "TSatlog.h"
       
    25 
       
    26 #ifdef __LOGGER__
       
    27 
       
    28 GLDEF_D CTestLogger* aTestLoggerContext;
       
    29 
       
    30 #define KLogFileName _L("C:\\TSATCLI.LOG")
       
    31 #define	KGenericBufferSize	(150)
       
    32 
       
    33 CTestLogger* CTestLogger::NewL()
       
    34 	{
       
    35 	CTestLogger* aA=new(ELeave) CTestLogger();
       
    36 	CleanupStack::PushL(aA);
       
    37 	aA->ConstructL();
       
    38 	CleanupStack::Pop();
       
    39 	return aA;
       
    40 	}
       
    41 
       
    42 CTestLogger::CTestLogger() : iValid(EFalse)
       
    43 	{}
       
    44 
       
    45 void CTestLogger::ConstructL()
       
    46 	{
       
    47 	iFs.Connect();
       
    48 	TInt ret=iFile.Open(iFs,KLogFileName,EFileShareAny|EFileWrite);
       
    49 	if(ret!=KErrNone)
       
    50 		ret=iFile.Create(iFs,KLogFileName,EFileShareAny|EFileWrite);
       
    51 	if(ret==KErrNone)
       
    52 		{
       
    53 		iValid=ETrue;
       
    54 		TInt aPos=0;
       
    55 		iFile.Seek(ESeekEnd,aPos);
       
    56 		ret=iFile.Write(_L8("----------New Log----------\015\012"));
       
    57 		}
       
    58 	}
       
    59 
       
    60 CTestLogger::~CTestLogger()
       
    61 	{
       
    62 	if(iValid)
       
    63 		iFile.Close();
       
    64 	iFs.Close();
       
    65 	}
       
    66 
       
    67 void CTestLogger::Destruct()
       
    68 	{
       
    69 	CTestLogger* aContext=aTestLoggerContext;
       
    70 	delete aContext;
       
    71 	aContext=NULL;
       
    72 	}
       
    73 
       
    74 void CTestLogger::Write(const TDesC8& aText)
       
    75 	{
       
    76 	CTestLogger* aContext=aTestLoggerContext;
       
    77 	if(aContext==NULL)
       
    78 		{
       
    79 		TRAPD(ret,aContext=CTestLogger::NewL());
       
    80 		if (ret==KErrNone)
       
    81 			aTestLoggerContext=aContext;
       
    82 		else return;
       
    83 		}
       
    84 	if(aContext->iValid)
       
    85 		aContext->WriteRecord(aText);
       
    86 	}
       
    87 
       
    88 void CTestLogger::WriteFormat(TRefByValue<const TDesC8> aFmt,...)
       
    89 	{
       
    90 	TBuf8<KGenericBufferSize> aBuf;
       
    91     VA_LIST list;
       
    92     VA_START(list,aFmt);
       
    93     aBuf.FormatList(aFmt,list);
       
    94 	TChar aChar;
       
    95 	for(TInt i=0;i<aBuf.Length();i++)
       
    96 		{
       
    97 		aChar=aBuf[i];
       
    98 		if( !((aChar.IsPrint()) || (aChar=='\n') || (aChar=='\r') || (aChar=='\t')))
       
    99 			aBuf[i]='.';
       
   100 		}
       
   101 	CTestLogger* aContext=aTestLoggerContext;
       
   102 	if(aContext==NULL)
       
   103 		{
       
   104 		TRAPD(ret,aContext=CTestLogger::NewL());
       
   105 		if (ret==KErrNone)
       
   106 			aTestLoggerContext=aContext;
       
   107 		else return;
       
   108 		}
       
   109 	if(aContext->iValid)
       
   110 		aContext->WriteRecord(aBuf);
       
   111 	}
       
   112 #pragma warning(disable:4710)
       
   113 void CTestLogger::WriteRecord(const TDesC8& aText)
       
   114 	{	
       
   115 	if(iValid)
       
   116 		{
       
   117 		TBuf8<KGenericBufferSize> buf;
       
   118 		TTime now;
       
   119 		now.UniversalTime();
       
   120 		TDateTime dateTime;
       
   121 		dateTime = now.DateTime();
       
   122 		buf.Format(_L8 ("%02d.%02d:%02d:%06d "),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond());
       
   123 		buf.AppendFormat(_L8("%S\015\012"),&aText);
       
   124 		iFile.Write(buf);
       
   125 		iFile.Flush();
       
   126 		}
       
   127 	}
       
   128 #pragma warning(default:4710)
       
   129 #endif