|
1 /* |
|
2 * Copyright (c) 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 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 WEBUTILS_LOGGER_H |
|
20 #define WEBUTILS_LOGGER_H |
|
21 |
|
22 |
|
23 #if defined ( _DEBUG ) || defined ( _WEBUTILS_LOG_ ) |
|
24 |
|
25 // INCLUDES |
|
26 #include <flogger.h> |
|
27 #include <e32debug.h> |
|
28 |
|
29 enum TLoggingSelectors |
|
30 { |
|
31 EEnterFunction = 1, |
|
32 ELeaveFunction, |
|
33 EWriteLog |
|
34 }; |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 // Macros to be substituted |
|
39 _LIT( KLogMessageAppBanner, "WebUtils: module (%d.%d.%d) started" ); |
|
40 _LIT( KLogExit, "WebUtils: module exit" ); |
|
41 _LIT( KLogTimeFormatString, "%H:%T:%S:%*C3" ); |
|
42 _LIT8( KLogEnterFn, "ENTRY " ); |
|
43 _LIT8( KLogLeaveFn, "EXIT " ); |
|
44 |
|
45 // ATTENTION!!! We're depending on FLogger DLL, because it presumes the |
|
46 // existance of C:\LOGS directory. |
|
47 _LIT( KFLoggerDependency, "c:\\logs\\" ); |
|
48 _LIT( KDoubleBackSlash, "\\" ); |
|
49 _LIT( KLogDir, "WebUtils" ); |
|
50 _LIT( KLogFile, "WebUtils.log" ); |
|
51 |
|
52 /** |
|
53 * Use this macro in order to initialize logger : |
|
54 * - create log directory, |
|
55 * - write version information into the log file |
|
56 */ |
|
57 // temporary remove directory creating from webutils --> causes crash. |
|
58 //#define LOG_CREATE { TFileName path( KFLoggerDependency ); path.Append( KLogDir ); path.Append( KDoubleBackSlash ); RFs& fs = CEikonEnv::Static()->FsSession(); fs.MkDirAll( path ); RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeOverwrite, KLogMessageAppBanner ); } |
|
59 #define LOG_CREATE |
|
60 |
|
61 /** |
|
62 * Use this macro for writing information about exiting. |
|
63 */ |
|
64 #define LOG_DELETE { RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, KLogExit ); } |
|
65 |
|
66 /** |
|
67 * Use this function at the entry point of any functions. |
|
68 * @param a Entry information of the method. |
|
69 */ |
|
70 #define LOG_ENTERFN( a ) write_log (EEnterFunction, a) |
|
71 /** |
|
72 * Use this function right before you leave the method. |
|
73 * @param a Leaving information of the method. |
|
74 */ |
|
75 #define LOG_LEAVEFN( a ) write_log (ELeaveFunction, a) |
|
76 |
|
77 /** |
|
78 * Use this function at any points of a function for logging the current state. |
|
79 * @param a String to be written into logfile about the current state |
|
80 */ |
|
81 #define LOG_WRITE( a ) write_log (EWriteLog, a) |
|
82 /** |
|
83 * Use this function at any points of a function for logging the current state. |
|
84 * You can use printf-like formats, but with only one parameter to be substituted.. |
|
85 * @param a Format string, |
|
86 * @param b Parameter to be substituted. |
|
87 */ |
|
88 #define LOG_WRITE_FORMAT( a, b ) write_log (EWriteLog, a, b) |
|
89 |
|
90 inline void write_log (TInt aSelector, const char* aFmt,...) //lint !e960 |
|
91 { |
|
92 TBuf8<256> buf; |
|
93 { |
|
94 VA_LIST ap;//lint !e960 |
|
95 TPtrC8 fmt((unsigned char *)aFmt); |
|
96 VA_START(ap, aFmt); //lint !e960 |
|
97 buf.FormatList(fmt, ap); |
|
98 VA_END(ap); //lint !e960 |
|
99 } |
|
100 switch(aSelector) |
|
101 { |
|
102 case EEnterFunction: |
|
103 buf.Insert(0, KLogEnterFn); |
|
104 break; |
|
105 case ELeaveFunction: |
|
106 buf.Insert(0, KLogLeaveFn); |
|
107 break; |
|
108 default: |
|
109 break; |
|
110 } |
|
111 |
|
112 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, buf); |
|
113 |
|
114 TBuf<256> tempBuf; |
|
115 tempBuf.Copy( buf ); |
|
116 RDebug::Print( tempBuf ); |
|
117 } |
|
118 |
|
119 #define LOG_HEXDUMP(aBuf) {RFileLogger::HexDump(KWebUtilsLogDir, KWebUtilsLogFile, EFileLoggingModeAppend, ((const TText *)" "), ((const TText *)" "), aBuf.Ptr(), aBuf.Size());} |
|
120 |
|
121 |
|
122 #else // _DEBUG || _WebUtils_LOG |
|
123 |
|
124 // Empty macros |
|
125 #define LOG_CREATE |
|
126 #define LOG_DELETE |
|
127 #define LOG_ENTERFN( a ) |
|
128 #define LOG_LEAVEFN( a ) |
|
129 #define LOG_WRITE( a ) |
|
130 #define LOG_WRITE_FORMAT( a, b ) |
|
131 #define LOG_HEXDUMP( a) |
|
132 |
|
133 #endif // _DEBUG || _WebUtils_LOG |
|
134 |
|
135 #endif // WebUtils_LOGGER_H |
|
136 |
|
137 // End of file |