|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "logservpanic.h" |
|
17 #include "LogServSqlStrings.h" |
|
18 |
|
19 // |
|
20 // RMessage::Panic() also completes the message. This is: |
|
21 // (a) important for efficient cleanup within the kernel |
|
22 // (b) a problem if the message is completed a second time |
|
23 // |
|
24 void PanicClientL(const RMessage2& aMessage, TLogServPanic aPanic) |
|
25 { |
|
26 aMessage.Panic(KLogServ, aPanic); |
|
27 User::Leave(KLogPanicLeave); |
|
28 } |
|
29 |
|
30 void PanicClient(const RMessage2& aMessage, TLogServPanic aPanic) |
|
31 { |
|
32 aMessage.Panic(KLogServ, aPanic); |
|
33 } |
|
34 |
|
35 #pragma BullseyeCoverage off |
|
36 |
|
37 void Panic(TLogServPanic aPanic) |
|
38 { |
|
39 User::Panic(KLogServ, aPanic); |
|
40 } |
|
41 |
|
42 #pragma BullseyeCoverage on |
|
43 |
|
44 #ifdef LOGGING_ENABLED |
|
45 |
|
46 const TInt KLogEngLogBufferSize = 256; |
|
47 |
|
48 void Log::New() |
|
49 { |
|
50 _LIT(KNewLogText, "===== NEW LOG ====="); |
|
51 // |
|
52 RFileLogger logger; |
|
53 TInt ret=logger.Connect(); |
|
54 if (ret==KErrNone) |
|
55 { |
|
56 logger.CreateLog(KLogFolder, KLogFileName, EFileLoggingModeOverwrite); |
|
57 logger.Write(KNewLogText); |
|
58 } |
|
59 logger.Close(); |
|
60 } |
|
61 |
|
62 void Log::Write(const TDesC& aText) |
|
63 { |
|
64 PruneLogFile(); |
|
65 |
|
66 RFileLogger logger; |
|
67 TInt ret=logger.Connect(); |
|
68 if (ret==KErrNone) |
|
69 { |
|
70 logger.SetDateAndTime(EFalse,EFalse); |
|
71 logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend); |
|
72 TBuf<KLogEngLogBufferSize> buf; |
|
73 |
|
74 // The debug log uses hometime rather than UTC for its timestamps. This is |
|
75 // purely a debugging aid. |
|
76 TTime now; |
|
77 now.HomeTime(); |
|
78 TDateTime dateTime; |
|
79 dateTime = now.DateTime(); |
|
80 buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
81 buf.AppendFormat(KTextFormat,&aText); |
|
82 |
|
83 logger.Write(buf); |
|
84 } |
|
85 |
|
86 logger.Close(); |
|
87 } |
|
88 |
|
89 void Log::WriteFormat(TRefByValue<const TDesC> aFmt,...) |
|
90 { |
|
91 VA_LIST list; |
|
92 VA_START(list,aFmt); |
|
93 |
|
94 PruneLogFile(); |
|
95 |
|
96 TBuf<2*KLogEngLogBufferSize> buf; |
|
97 buf.SetMax(); |
|
98 buf.FillZ(); |
|
99 |
|
100 // The debug log uses hometime rather than UTC for its timestamps. This is |
|
101 // purely a debugging aid. |
|
102 TTime now; |
|
103 now.HomeTime(); |
|
104 TDateTime dateTime; |
|
105 dateTime = now.DateTime(); |
|
106 buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
107 buf.AppendFormatList(aFmt, list ); |
|
108 |
|
109 RFileLogger logger; |
|
110 TInt ret=logger.Connect(); |
|
111 if (ret==KErrNone) |
|
112 { |
|
113 logger.SetDateAndTime(EFalse,EFalse); |
|
114 logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend); |
|
115 logger.Write(buf); |
|
116 } |
|
117 |
|
118 logger.Close(); |
|
119 |
|
120 } |
|
121 |
|
122 void Log::PruneLogFile() |
|
123 { |
|
124 const TInt KMaxLogSize = 1024 * 500; |
|
125 // |
|
126 _LIT(KBaseFolder, "_:\\Logs\\"); |
|
127 TFileName fileName(KBaseFolder); |
|
128 fileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive()); |
|
129 fileName.Append(KLogFolder); |
|
130 fileName.Append(KPathDelimiter); |
|
131 fileName.Append(KLogFileName); |
|
132 // |
|
133 RFs fsSession; |
|
134 if (fsSession.Connect() == KErrNone) |
|
135 { |
|
136 TEntry entry; |
|
137 if (fsSession.Entry(fileName, entry) == KErrNone) |
|
138 { |
|
139 // Check size and delete if its too big |
|
140 if (entry.iSize >= KMaxLogSize) |
|
141 { |
|
142 TInt fileDeleteErr=fsSession.Delete(fileName); |
|
143 // If a debug build - record error |
|
144 #ifdef _DEBUG |
|
145 if (fileDeleteErr != KErrNone) |
|
146 { |
|
147 RDebug::Print(_L("Log::PruneLogFile - Failed to delete file. Error = %d"), fileDeleteErr); |
|
148 } |
|
149 #else |
|
150 (void)fileDeleteErr; |
|
151 #endif |
|
152 } |
|
153 } |
|
154 } |
|
155 fsSession.Close(); |
|
156 } |
|
157 |
|
158 #endif |