os/security/cryptomgmtlibs/securitytestfw/test/loggertemplate/slogger.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/loggertemplate/slogger.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,72 @@
     1.4 +/*
     1.5 +* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "slogger.h"
    1.23 +
    1.24 +#include <e32base.h>
    1.25 +#include <e32svr.h>
    1.26 +#include <f32file.h>
    1.27 +
    1.28 +
    1.29 +// Very simple logging code. This will thrash the file server by
    1.30 +// creating a new session to it for every line. Create the file
    1.31 +// c:\logs\ct.txt to turn on logging.
    1.32 +EXPORT_C void SLogger::Log(const TDesC& aLogFileName, const TDesC& aString,
    1.33 +							const TDesC8& aSourceFileName, TInt aLineNumber)
    1.34 +	{
    1.35 +	// Open the file server and file
    1.36 +	RFs fs;
    1.37 +	fs.Connect();
    1.38 +	RFile file;
    1.39 +	TInt error = file.Open(fs, aLogFileName, EFileWrite|EFileShareAny);
    1.40 +	// If the file doesn't exist, exit
    1.41 +	if (error != KErrNone)
    1.42 +		{
    1.43 +		fs.Close();
    1.44 +		return;
    1.45 +		}
    1.46 +	// Seek to the end of the file
    1.47 +	TInt tmp = 0;
    1.48 +	file.Seek(ESeekEnd, tmp);
    1.49 +
    1.50 +	// And do some logging
    1.51 +	// Name of the file where the Log function was called
    1.52 +	file.Write(aSourceFileName);
    1.53 +	// Number of the line where the Log function was called
    1.54 +	_LIT8(KLineNumber, ",%d:");
    1.55 +	TBuf8<80> buf;
    1.56 +	buf.Format(KLineNumber, aLineNumber);
    1.57 +	file.Write(buf);
    1.58 +	buf.Copy(aString);
    1.59 +	file.Write(buf);
    1.60 +	_LIT8(KEnd, "\r\n");
    1.61 +	file.Write(KEnd());
    1.62 +
    1.63 +	// Close and tidy up
    1.64 +	file.Close();
    1.65 +	fs.Close();
    1.66 +	}
    1.67 +	
    1.68 +EXPORT_C void SLogger::Log(const TDesC& aLogFileName, TInt aInt, 
    1.69 +							const TDesC8& aSourceFileName, TInt aLineNumber)
    1.70 +	{
    1.71 +	TBuf<20> str;
    1.72 +	str.Num(aInt);
    1.73 +	Log(aLogFileName, str, aSourceFileName, aLineNumber);
    1.74 +	}
    1.75 +