1 /* |
|
2 * Copyright (c) 2002-2006 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: Implemented logger functionality of the module |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef BROWSER_LOGGER_H |
|
20 #define BROWSER_LOGGER_H |
|
21 |
|
22 #if defined( I__BROWSER_LOG_ENABLED ) || defined ( I__BROWSER_PERF_LOG_ENABLED ) |
|
23 |
|
24 // INCLUDES |
|
25 #include <bldvariant.hrh> |
|
26 #include <e32std.h> |
|
27 #include <e32def.h> |
|
28 #include <e32cmn.h> |
|
29 #include <flogger.h> |
|
30 |
|
31 |
|
32 // log files are stored to KDebugLogDirFull folder |
|
33 _LIT(KDebugLogDependency, "C:\\Logs\\"); |
|
34 _LIT(KDebugLogDoubleBackSlash, "\\"); |
|
35 |
|
36 _LIT( KDebugLogDir, "Browser"); |
|
37 _LIT( KDebugLogFile, "Browser.log"); |
|
38 _LIT( KDebugPerfLogFile, "BrowserPerf.log"); |
|
39 _LIT( KLogMessageAppBanner, "Browser: module (%d.%d.%d) started" ); |
|
40 _LIT( KPerLogBanner, "*************Performance Logging *****************"); |
|
41 // _LIT( KDebugLogTimeFormatString,"%H:%T:%S:%*C3" ); |
|
42 _LIT( KDebugLogExit, "Browser: module exit" ); |
|
43 |
|
44 #endif |
|
45 |
|
46 #if defined( I__BROWSER_LOG_ENABLED ) |
|
47 |
|
48 // MACROS |
|
49 // indentation is not supported by the hardware at this moment |
|
50 #if defined( __WINSCW__ ) |
|
51 #define I__BROWSER_LOG_INDENT |
|
52 #endif |
|
53 |
|
54 /** |
|
55 * Use this macro in order to initialize logger : |
|
56 * - create log directory, |
|
57 * - write version information into the log file |
|
58 */ |
|
59 #define LOG_CREATE { TFileName path( KDebugLogDependency ); \ |
|
60 path.Append( KDebugLogDir ); \ |
|
61 path.Append( KDebugLogDoubleBackSlash ); \ |
|
62 RFs& fs = CEikonEnv::Static()->FsSession(); \ |
|
63 fs.MkDirAll( path ); \ |
|
64 RFileLogger::WriteFormat( KDebugLogDir, KDebugLogFile, EFileLoggingModeOverwrite, KLogMessageAppBanner ); \ |
|
65 } |
|
66 |
|
67 /** |
|
68 * Use this macro for writing information about exiting. |
|
69 */ |
|
70 #define LOG_DELETE { RFileLogger::Write( KDebugLogDir, KDebugLogFile, EFileLoggingModeAppend, KDebugLogExit ); } |
|
71 |
|
72 /** |
|
73 * Use this function at any points of a function for writing a hex dump |
|
74 * of the specified data to the log. |
|
75 * @param p The data the is to be converted to a hex string. |
|
76 * @param l How many of the characters in p are to be converted. |
|
77 * Conversion always starts from position 0 within p. |
|
78 */ |
|
79 //#define LOG_WRITE_HEXDUMP( p, l ) { RFileLogger::HexDump( KDebugLogDir, KDebugLogFile, EFileLoggingModeAppend, _S("RLog_Ex"), _S("RL_cont"), p, l ); } |
|
80 |
|
81 // ------------------------------------------------- |
|
82 |
|
83 class MLoggerProvider |
|
84 { |
|
85 public: |
|
86 virtual TInt* LoggerIndent() = 0; |
|
87 virtual void LoggerIndentIncrement( TInt aValue ) = 0; |
|
88 virtual void LoggerIndentDecrement( TInt aValue ) = 0; |
|
89 }; |
|
90 |
|
91 class CBrowserLogger: public CBase |
|
92 { |
|
93 public: |
|
94 CBrowserLogger( const TDesC& aFunc ); |
|
95 ~CBrowserLogger(); |
|
96 |
|
97 /** |
|
98 * Write formatted log. |
|
99 * @param aFmt Format string. |
|
100 */ |
|
101 static void Write( TRefByValue<const TDesC16> aFmt, ... ); |
|
102 |
|
103 /** |
|
104 * Write formatted log. |
|
105 * @param aFmt Format string. |
|
106 * @param aList Variable argument list. |
|
107 */ |
|
108 static void Write( TRefByValue<const TDesC16> aFmt, VA_LIST& aList ); |
|
109 |
|
110 /** |
|
111 * Write formatted log. |
|
112 * @param aFmt Format string. |
|
113 */ |
|
114 static void Write(TRefByValue<const TDesC8> aFmt, ... ); |
|
115 |
|
116 /** |
|
117 * Write formatted log. |
|
118 * @param aFmt Format string. |
|
119 * @param aList Variable argument list. |
|
120 */ |
|
121 static void Write( TRefByValue<const TDesC8> aFmt, VA_LIST& aList ); |
|
122 |
|
123 protected: |
|
124 TPtrC iFunc; |
|
125 const MLoggerProvider* iOwner; |
|
126 // make the indentation available by 'static' keyword |
|
127 #if defined ( I__BROWSER_LOG_INDENT ) |
|
128 static |
|
129 #endif |
|
130 TInt iIndent; |
|
131 }; |
|
132 |
|
133 // ------------------------------------------------- |
|
134 // Usage: |
|
135 // - call LOG_ENTERFN( "function name" ); at entry point of a function |
|
136 // otherwise BROWSER_LOG call won't work |
|
137 // - call BROWSER_LOG( ( _L( "log string" ) ) ); OR |
|
138 // you can add parameters to this call like this: |
|
139 // - BROWSER_LOG( ( _L( "format string: %d" ), value ) ); |
|
140 // ------------------------------------------------- |
|
141 // future development if _L() will be removed: |
|
142 // #define _BL( a ) TPtrC( _S( a ) ) |
|
143 // BROWSER_LOG( ( _BL( "format string: %d" ), a ) ) |
|
144 // ------------------------------------------------- |
|
145 |
|
146 #define LOG_ENTERFN( a ) _LIT( _br_temp_log_string18, a ); \ |
|
147 CBrowserLogger _br_entry_exit( _br_temp_log_string18 ) |
|
148 #define BROWSER_LOG( _params_ ) \ |
|
149 _br_entry_exit.Write _params_ |
|
150 #define LOG_WRITE( _params_ ) \ |
|
151 BROWSER_LOG( ( _L( _params_ ) ) ) |
|
152 #define LOG_WRITE_FORMAT( _format_, _params_ ) \ |
|
153 BROWSER_LOG( ( _L( _format_ ), _params_ ) ) |
|
154 |
|
155 #else // I__BROWSER_LOG_ENABLED |
|
156 |
|
157 // Empty macros |
|
158 #define LOG_CREATE |
|
159 #define LOG_DELETE |
|
160 #define LOG_ENTERFN( a ) |
|
161 #define LOG_WRITE( a ) |
|
162 #define LOG_WRITE_FORMAT( a, b ) |
|
163 #define LOG_WRITE_TIMESTAMP( a ) |
|
164 #define LOG_WRITE_HEXDUMP( p, l ) |
|
165 #define BROWSER_LOG( a ) |
|
166 |
|
167 #endif // I__BROWSER_LOG_ENABLED |
|
168 |
|
169 |
|
170 #ifdef I__BROWSER_PERF_LOG_ENABLED |
|
171 |
|
172 /** |
|
173 * Use this macro in order to initialize performance logger: |
|
174 * - create log directory, |
|
175 * |
|
176 */ |
|
177 #define PERFLOG_CREATE { TFileName path( KDebugLogDependency ); \ |
|
178 path.Append( KDebugLogDir ); \ |
|
179 path.Append( KDebugLogDoubleBackSlash ); \ |
|
180 RFs& fs = CEikonEnv::Static()->FsSession(); \ |
|
181 fs.MkDirAll( path ); \ |
|
182 RFileLogger::WriteFormat( KDebugLogDir, KDebugPerfLogFile, EFileLoggingModeOverwrite, KPerLogBanner);\ |
|
183 } |
|
184 |
|
185 #define PERFLOG_LOCAL_INIT \ |
|
186 TTime __time1_brbrbr;\ |
|
187 TTime __time2_brbrbr;\ |
|
188 TTimeIntervalMicroSeconds diff_brbrbr; |
|
189 |
|
190 |
|
191 #define PERFLOG_STOPWATCH_START \ |
|
192 __time1_brbrbr.HomeTime(); |
|
193 |
|
194 #define PERFLOG_STOPWATCH_STOP \ |
|
195 __time2_brbrbr.HomeTime();\ |
|
196 diff_brbrbr = __time2_brbrbr.MicroSecondsFrom( __time1_brbrbr ); |
|
197 |
|
198 #define PERFLOG_WRITE( _param_ ){\ |
|
199 _LIT( __perf_temp_1234_, "%S took %Ld ms" );\ |
|
200 _LIT(__perf_temp_param, _param_ );\ |
|
201 RFileLogger::WriteFormat( KDebugLogDir, KDebugPerfLogFile, EFileLoggingModeAppend, __perf_temp_1234_, &__perf_temp_param(), diff_brbrbr .Int64() );\ |
|
202 } |
|
203 |
|
204 #define PERFLOG_STOP_WRITE( _params_ )\ |
|
205 PERFLOG_STOPWATCH_STOP\ |
|
206 PERFLOG_WRITE( _params_ ) |
|
207 |
|
208 //It may look ugly in code |
|
209 #define PERF( _a, _b ) \ |
|
210 {\ |
|
211 PERFLOG_LOCAL_INIT\ |
|
212 PERFLOG_STOPWATCH_START\ |
|
213 _b;\ |
|
214 PERFLOG_STOP_WRITE( _a )\ |
|
215 } |
|
216 |
|
217 |
|
218 #else |
|
219 |
|
220 #define PERFLOG_CREATE |
|
221 #define PERFLOG_LOCAL_INIT |
|
222 #define PERFLOG_STOPWATCH_START |
|
223 #define PERFLOG_STOPWATCH_STOP |
|
224 #define PERFLOG_WRITE(a) |
|
225 #define PERFLOG_STOP_WRITE(a) |
|
226 #define PERF( _a, _b ) _b |
|
227 #endif |
|
228 |
|
229 |
|
230 |
|
231 #endif // BROWSER_LOGGER_H |
|
232 |
|
233 // End of file |
|