os/security/cryptomgmtlibs/securitytestfw/test/loggertemplate/slogger.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "slogger.h"
sl@0
    20
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <e32svr.h>
sl@0
    23
#include <f32file.h>
sl@0
    24
sl@0
    25
sl@0
    26
// Very simple logging code. This will thrash the file server by
sl@0
    27
// creating a new session to it for every line. Create the file
sl@0
    28
// c:\logs\ct.txt to turn on logging.
sl@0
    29
EXPORT_C void SLogger::Log(const TDesC& aLogFileName, const TDesC& aString,
sl@0
    30
							const TDesC8& aSourceFileName, TInt aLineNumber)
sl@0
    31
	{
sl@0
    32
	// Open the file server and file
sl@0
    33
	RFs fs;
sl@0
    34
	fs.Connect();
sl@0
    35
	RFile file;
sl@0
    36
	TInt error = file.Open(fs, aLogFileName, EFileWrite|EFileShareAny);
sl@0
    37
	// If the file doesn't exist, exit
sl@0
    38
	if (error != KErrNone)
sl@0
    39
		{
sl@0
    40
		fs.Close();
sl@0
    41
		return;
sl@0
    42
		}
sl@0
    43
	// Seek to the end of the file
sl@0
    44
	TInt tmp = 0;
sl@0
    45
	file.Seek(ESeekEnd, tmp);
sl@0
    46
sl@0
    47
	// And do some logging
sl@0
    48
	// Name of the file where the Log function was called
sl@0
    49
	file.Write(aSourceFileName);
sl@0
    50
	// Number of the line where the Log function was called
sl@0
    51
	_LIT8(KLineNumber, ",%d:");
sl@0
    52
	TBuf8<80> buf;
sl@0
    53
	buf.Format(KLineNumber, aLineNumber);
sl@0
    54
	file.Write(buf);
sl@0
    55
	buf.Copy(aString);
sl@0
    56
	file.Write(buf);
sl@0
    57
	_LIT8(KEnd, "\r\n");
sl@0
    58
	file.Write(KEnd());
sl@0
    59
sl@0
    60
	// Close and tidy up
sl@0
    61
	file.Close();
sl@0
    62
	fs.Close();
sl@0
    63
	}
sl@0
    64
	
sl@0
    65
EXPORT_C void SLogger::Log(const TDesC& aLogFileName, TInt aInt, 
sl@0
    66
							const TDesC8& aSourceFileName, TInt aLineNumber)
sl@0
    67
	{
sl@0
    68
	TBuf<20> str;
sl@0
    69
	str.Num(aInt);
sl@0
    70
	Log(aLogFileName, str, aSourceFileName, aLineNumber);
sl@0
    71
	}
sl@0
    72