sl@0: /* sl@0: * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "slogger.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: // Very simple logging code. This will thrash the file server by sl@0: // creating a new session to it for every line. Create the file sl@0: // c:\logs\ct.txt to turn on logging. sl@0: EXPORT_C void SLogger::Log(const TDesC& aLogFileName, const TDesC& aString, sl@0: const TDesC8& aSourceFileName, TInt aLineNumber) sl@0: { sl@0: // Open the file server and file sl@0: RFs fs; sl@0: fs.Connect(); sl@0: RFile file; sl@0: TInt error = file.Open(fs, aLogFileName, EFileWrite|EFileShareAny); sl@0: // If the file doesn't exist, exit sl@0: if (error != KErrNone) sl@0: { sl@0: fs.Close(); sl@0: return; sl@0: } sl@0: // Seek to the end of the file sl@0: TInt tmp = 0; sl@0: file.Seek(ESeekEnd, tmp); sl@0: sl@0: // And do some logging sl@0: // Name of the file where the Log function was called sl@0: file.Write(aSourceFileName); sl@0: // Number of the line where the Log function was called sl@0: _LIT8(KLineNumber, ",%d:"); sl@0: TBuf8<80> buf; sl@0: buf.Format(KLineNumber, aLineNumber); sl@0: file.Write(buf); sl@0: buf.Copy(aString); sl@0: file.Write(buf); sl@0: _LIT8(KEnd, "\r\n"); sl@0: file.Write(KEnd()); sl@0: sl@0: // Close and tidy up sl@0: file.Close(); sl@0: fs.Close(); sl@0: } sl@0: sl@0: EXPORT_C void SLogger::Log(const TDesC& aLogFileName, TInt aInt, sl@0: const TDesC8& aSourceFileName, TInt aLineNumber) sl@0: { sl@0: TBuf<20> str; sl@0: str.Num(aInt); sl@0: Log(aLogFileName, str, aSourceFileName, aLineNumber); sl@0: } sl@0: