First public contribution.
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "ct/logger.h"
22 #if defined(_DEBUG) && defined(__CT_LOGGING__)
24 _LIT(KLogFilename, "\\logs\\security\\cryptotokens.txt");
26 _LIT8(KNewLine, "\r\n");
32 return reinterpret_cast<TInt>(Dll::Tls());
35 static void SetIndent(TInt aIndent)
37 Dll::SetTls(reinterpret_cast<TAny*>(aIndent));
40 EXPORT_C void CTLogger::Log(TAny* aObject, TRefByValue<const TDesC16> aFmt, ...)
44 data.AppendFormat(_L("%08x: "), aObject);
46 for (TInt i = 0 ; i < Indent() ; ++i)
53 data.AppendFormatList(aFmt, args);
56 TRAPD(err, LogL(data));
57 ASSERT(err == KErrNone);
60 EXPORT_C void CTLogger::UpdateIndent(TInt aInc)
62 TInt newIndent = Indent() + aInc;
63 ASSERT(newIndent >= 0);
67 void CTLogger::LogL(const TDesC& aString)
69 // Open the file server and file
71 User::LeaveIfError(fs.Connect());
72 CleanupClosePushL(fs);
74 // Open the file or create it if doesn't exist, create it
76 TDriveUnit sysDrive (fs.GetSystemDrive());
77 TBuf<128> logFile (sysDrive.Name());
78 logFile.Append(KLogFilename);
80 TInt error = file.Open(fs, logFile, EFileWrite|EFileShareAny);
81 if (error == KErrNotFound)
83 error = file.Create(fs, logFile, EFileWrite|EFileShareAny);
85 User::LeaveIfError(error);
86 CleanupClosePushL(file);
88 // Seek to the end of the file
90 file.Seek(ESeekEnd, tmp);
92 // And do some logging
99 CleanupStack::PopAndDestroy(2, &fs);
104 EXPORT_C void CTLogger::Log(TAny* /*aObject*/, TRefByValue<const TDesC16> /*aFmt*/, ...)
109 EXPORT_C void CTLogger::UpdateIndent(TInt /*aInc*/)