|
1 /* |
|
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "slogger.h" |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <e32svr.h> |
|
23 #include <f32file.h> |
|
24 |
|
25 |
|
26 // Very simple logging code. This will thrash the file server by |
|
27 // creating a new session to it for every line. Create the file |
|
28 // c:\logs\ct.txt to turn on logging. |
|
29 EXPORT_C void SLogger::Log(const TDesC& aLogFileName, const TDesC& aString, |
|
30 const TDesC8& aSourceFileName, TInt aLineNumber) |
|
31 { |
|
32 // Open the file server and file |
|
33 RFs fs; |
|
34 fs.Connect(); |
|
35 RFile file; |
|
36 TInt error = file.Open(fs, aLogFileName, EFileWrite|EFileShareAny); |
|
37 // If the file doesn't exist, exit |
|
38 if (error != KErrNone) |
|
39 { |
|
40 fs.Close(); |
|
41 return; |
|
42 } |
|
43 // Seek to the end of the file |
|
44 TInt tmp = 0; |
|
45 file.Seek(ESeekEnd, tmp); |
|
46 |
|
47 // And do some logging |
|
48 // Name of the file where the Log function was called |
|
49 file.Write(aSourceFileName); |
|
50 // Number of the line where the Log function was called |
|
51 _LIT8(KLineNumber, ",%d:"); |
|
52 TBuf8<80> buf; |
|
53 buf.Format(KLineNumber, aLineNumber); |
|
54 file.Write(buf); |
|
55 buf.Copy(aString); |
|
56 file.Write(buf); |
|
57 _LIT8(KEnd, "\r\n"); |
|
58 file.Write(KEnd()); |
|
59 |
|
60 // Close and tidy up |
|
61 file.Close(); |
|
62 fs.Close(); |
|
63 } |
|
64 |
|
65 EXPORT_C void SLogger::Log(const TDesC& aLogFileName, TInt aInt, |
|
66 const TDesC8& aSourceFileName, TInt aLineNumber) |
|
67 { |
|
68 TBuf<20> str; |
|
69 str.Num(aInt); |
|
70 Log(aLogFileName, str, aSourceFileName, aLineNumber); |
|
71 } |