1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/cryptotokenfw/source/ctframework/CTLogger.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,114 @@
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 "ct/logger.h"
1.23 +#include <f32file.h>
1.24 +
1.25 +#if defined(_DEBUG) && defined(__CT_LOGGING__)
1.26 +
1.27 +_LIT(KLogFilename, "\\logs\\security\\cryptotokens.txt");
1.28 +_LIT(KIndent, " ");
1.29 +_LIT8(KNewLine, "\r\n");
1.30 +
1.31 +#define MAX_LEN 128
1.32 +
1.33 +static TInt Indent()
1.34 + {
1.35 + return reinterpret_cast<TInt>(Dll::Tls());
1.36 + }
1.37 +
1.38 +static void SetIndent(TInt aIndent)
1.39 + {
1.40 + Dll::SetTls(reinterpret_cast<TAny*>(aIndent));
1.41 + }
1.42 +
1.43 +EXPORT_C void CTLogger::Log(TAny* aObject, TRefByValue<const TDesC16> aFmt, ...)
1.44 + {
1.45 + TBuf<MAX_LEN> data;
1.46 +
1.47 + data.AppendFormat(_L("%08x: "), aObject);
1.48 +
1.49 + for (TInt i = 0 ; i < Indent() ; ++i)
1.50 + {
1.51 + data.Append(KIndent);
1.52 + }
1.53 +
1.54 + VA_LIST args;
1.55 + VA_START(args, aFmt);
1.56 + data.AppendFormatList(aFmt, args);
1.57 + VA_END(args);
1.58 +
1.59 + TRAPD(err, LogL(data));
1.60 + ASSERT(err == KErrNone);
1.61 + }
1.62 +
1.63 +EXPORT_C void CTLogger::UpdateIndent(TInt aInc)
1.64 + {
1.65 + TInt newIndent = Indent() + aInc;
1.66 + ASSERT(newIndent >= 0);
1.67 + SetIndent(newIndent);
1.68 + }
1.69 +
1.70 +void CTLogger::LogL(const TDesC& aString)
1.71 + {
1.72 + // Open the file server and file
1.73 + RFs fs;
1.74 + User::LeaveIfError(fs.Connect());
1.75 + CleanupClosePushL(fs);
1.76 +
1.77 + // Open the file or create it if doesn't exist, create it
1.78 + RFile file;
1.79 + TDriveUnit sysDrive (fs.GetSystemDrive());
1.80 + TBuf<128> logFile (sysDrive.Name());
1.81 + logFile.Append(KLogFilename);
1.82 +
1.83 + TInt error = file.Open(fs, logFile, EFileWrite|EFileShareAny);
1.84 + if (error == KErrNotFound)
1.85 + {
1.86 + error = file.Create(fs, logFile, EFileWrite|EFileShareAny);
1.87 + }
1.88 + User::LeaveIfError(error);
1.89 + CleanupClosePushL(file);
1.90 +
1.91 + // Seek to the end of the file
1.92 + TInt tmp = 0;
1.93 + file.Seek(ESeekEnd, tmp);
1.94 +
1.95 + // And do some logging
1.96 + TBuf8<MAX_LEN> buf;
1.97 + buf.Copy(aString);
1.98 + file.Write(buf);
1.99 + file.Write(KNewLine);
1.100 +
1.101 + // Close and tidy up
1.102 + CleanupStack::PopAndDestroy(2, &fs);
1.103 + }
1.104 +
1.105 +#else
1.106 +
1.107 +EXPORT_C void CTLogger::Log(TAny* /*aObject*/, TRefByValue<const TDesC16> /*aFmt*/, ...)
1.108 + {
1.109 + User::Invariant();
1.110 + }
1.111 +
1.112 +EXPORT_C void CTLogger::UpdateIndent(TInt /*aInc*/)
1.113 + {
1.114 + User::Invariant();
1.115 + }
1.116 +
1.117 +#endif