|
1 /* |
|
2 * Copyright (c) 2002-2005 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 "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 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 #ifdef __CUSTOM_LOG_ENABLED__ |
|
26 |
|
27 // INCLUDE FILES |
|
28 #include "Logger.h" |
|
29 |
|
30 #include <f32file.h> |
|
31 |
|
32 void DoLog(const TDesC& aText) |
|
33 { |
|
34 static const TInt KLogEntryMaxLength = 128; |
|
35 _LIT(KLineFeed, "\n"); |
|
36 |
|
37 |
|
38 |
|
39 /** |
|
40 * Log time format (see TTime) is |
|
41 * Day-Month-Year Hours:Minutes:Seconds:Milliseconds |
|
42 * |
|
43 * Example: 30-12-2004 23:00:55:990 |
|
44 */ |
|
45 _LIT(KLogTimeFormat, "%F%D-%M-%Y %H:%T:%S:%*C3"); |
|
46 |
|
47 TBuf8<KLogEntryMaxLength> writeBuffer; |
|
48 RFs FileServer; |
|
49 RFile File; |
|
50 |
|
51 if(FileServer.Connect() != KErrNone) |
|
52 { |
|
53 FileServer.Close(); // just in case |
|
54 User::Panic(KLogPanicCategory(), KPanicFsConnectFailed); |
|
55 return; |
|
56 } |
|
57 |
|
58 // Open file for writing, if exists. Othervise create new file. |
|
59 if(File.Open(FileServer, KLogFileName(), EFileWrite) != KErrNone) |
|
60 { |
|
61 if(File.Create(FileServer, KLogFileName(), EFileWrite) != KErrNone) |
|
62 { |
|
63 FileServer.Close(); |
|
64 User::Panic(KLogPanicCategory(), KPanicFileCreateFailed); |
|
65 } |
|
66 } |
|
67 |
|
68 TTime currentTime; |
|
69 currentTime.UniversalTime(); |
|
70 TBuf<32> timeString; |
|
71 |
|
72 // currentTime is now in universal time. Convert it to home time. |
|
73 TLocale locale; |
|
74 TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset()); |
|
75 TTimeIntervalHours daylightSaving(0); |
|
76 if(locale.QueryHomeHasDaylightSavingOn()) |
|
77 { |
|
78 daylightSaving = 1; |
|
79 } |
|
80 currentTime = currentTime + universalTimeOffset + daylightSaving; |
|
81 TInt leaveCode(KErrNone); |
|
82 TRAP(leaveCode, currentTime.FormatL(timeString, KLogTimeFormat)); |
|
83 leaveCode = 0; // not used |
|
84 // Add LogString to the end of file and close the file |
|
85 TInt currentSize = 0, returnCode; |
|
86 writeBuffer.Append(timeString); |
|
87 writeBuffer.Append(_L(": ")); |
|
88 writeBuffer.Append(aText.Left(KLogEntryMaxLength-timeString.Length())); |
|
89 writeBuffer.Append(KLineFeed); |
|
90 File.Size(currentSize); |
|
91 returnCode = File.Write(currentSize, |
|
92 writeBuffer, |
|
93 writeBuffer.Length()); |
|
94 File.Close(); |
|
95 // Close file server session |
|
96 FileServer.Close(); |
|
97 |
|
98 if(returnCode != KErrNone) |
|
99 { |
|
100 User::Panic(KLogPanicCategory(), KPanicFileWriteFailed); |
|
101 } |
|
102 } |
|
103 |
|
104 #endif //__CUSTOM_LOG_ENABLED__ |