18 |
18 |
19 #ifndef __LOGGER_H__ |
19 #ifndef __LOGGER_H__ |
20 #define __LOGGER_H__ |
20 #define __LOGGER_H__ |
21 |
21 |
22 #ifdef _DEBUG |
22 #ifdef _DEBUG |
23 |
23 #ifdef __WINS__ |
24 // Define this to enable file logging |
24 // File logging for WINS |
25 #define __FLOGGING__ |
25 #define __FLOGGING__ |
|
26 #else |
|
27 // Logging with RDebug for target HW |
|
28 #define __CLOGGING__ |
|
29 //#define __FLOGGING__ // enable to log file on target HW |
|
30 #endif //__WINS__ |
26 |
31 |
27 #include <f32file.h> |
32 #include <f32file.h> |
28 #include <flogger.h> |
33 #include <flogger.h> |
29 #include <e32std.h> |
34 #include <e32std.h> |
30 #include <e32def.h> |
35 #include <e32def.h> |
31 |
|
32 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow |
|
33 { |
|
34 public: |
|
35 void Overflow(TDes16& /*aDes*/) {} |
|
36 }; |
|
37 |
|
38 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow |
|
39 { |
|
40 public: |
|
41 void Overflow(TDes8& /*aDes*/) {} |
|
42 }; |
|
43 |
36 |
44 _LIT(KLogDir,"MMS"); |
37 _LIT(KLogDir,"MMS"); |
45 _LIT(KLogFile,"MMSDataproviderLog.txt"); |
38 _LIT(KLogFile,"MMSDataproviderLog.txt"); |
46 _LIT( KLogFormat, "[MMSDS] %S"); |
39 _LIT( KLogFormat, "[MMSDS] %S"); |
47 |
40 |
48 _LIT(KTracePrefix16, "[MMSDS] "); |
41 _LIT(KLogEnterFn, "%S : Begin"); |
49 _LIT8(KTracePrefix8, "[MMSDS] "); |
42 _LIT(KLogLeaveFn, "%S : End"); |
50 _LIT8(KFuncEntryFormat8, "%S : Begin"); |
|
51 _LIT8(KFuncExitFormat8, "%S : End"); |
|
52 _LIT8(KFuncFormat8, "><%S"); |
|
53 |
|
54 const TInt KMaxLogLineLength = 512; |
|
55 |
43 |
56 /** |
44 /** |
57 * Old logging macros |
45 * Old logging macros, for public use |
58 */ |
46 */ |
59 #ifdef __FLOGGING__ |
47 #ifdef __FLOGGING__ |
60 #define LOG( AAA ) RFileLogger::Write( KLogDir,KLogFile,EFileLoggingModeAppend,AAA ) |
48 #define LOG( AAA ) RFileLogger::Write( KLogDir,KLogFile,EFileLoggingModeAppend,AAA ) |
61 #else |
49 #else |
62 #define LOG( AAA ) |
50 #define LOG( AAA ) |
63 #endif |
51 #endif |
|
52 #define LOG2( text, par1 ) { FPrint( text, par1 ); } |
64 |
53 |
65 |
54 |
66 // old function loggin macros |
55 /** |
67 #define LOGGER_ENTERFN( name ) {TRACE_FUNC_ENTRY;} |
56 * new logging macros, for public use |
68 #define LOGGER_LEAVEFN( name ) {TRACE_FUNC_EXIT;} |
57 */ |
|
58 #define LOGGER_ENTERFN( name ) {_LIT( temp, name ); FPrint( KLogEnterFn, &temp );} |
|
59 #define LOGGER_LEAVEFN( name ) {_LIT( temp, name ); FPrint( KLogLeaveFn, &temp );} |
69 |
60 |
70 #define LOGGER_WRITE( text ) {_LIT( KTemp, text ); FPrint( KTemp );} |
61 #define LOGGER_WRITE( text ) {_LIT( KTemp, text ); FPrint( KTemp );} |
71 #define LOGGER_WRITE_1( text,par1 ) {_LIT( KTemp, text ); FPrint( KTemp, par1 );} |
62 #define LOGGER_WRITE_1( text,par1 ) {_LIT( KTemp, text ); FPrint( KTemp, par1 );} |
72 #define LOGGER_WRITE_2( text,par1,par2 ) {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );} |
63 #define LOGGER_MSG_EC( text,par1 ) {_LIT( KTemp, text ); FPrint( KTemp, par1 );} |
73 |
|
74 // New function logging macros |
|
75 #define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);} |
|
76 #define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);} |
|
77 #define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);} |
|
78 |
64 |
79 |
65 |
80 // Declare the FPrint function |
66 // Declare the FPrint function |
81 inline void FPrint( TRefByValue<const TDesC16> aFmt, ...) |
67 inline void FPrint( TRefByValue<const TDesC> aFmt, ...) |
82 { |
68 { |
83 VA_LIST list; |
69 VA_LIST list; |
84 VA_START(list,aFmt); |
70 VA_START(list,aFmt); |
85 #if defined ( __FLOGGING__ ) |
71 #if defined ( __FLOGGING__ ) |
86 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list ); |
72 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list ); |
87 #endif |
73 #endif |
88 |
74 #if defined ( __CLOGGING__ ) |
89 TBuf16<KMaxLogLineLength> theFinalString; |
75 const TInt KMaxLogData = 0x200; |
90 theFinalString.Append(KTracePrefix16); |
76 TBuf< KMaxLogData > buf; |
91 TOverflowTruncate16 overflow; |
77 buf.FormatList( aFmt, list ); |
92 theFinalString.AppendFormatList(aFmt,list,&overflow); |
78 |
93 RDebug::Print(theFinalString); |
79 RDebug::Print( KLogFormat, &buf ); |
94 } |
80 #endif |
95 |
|
96 inline void FPrint(TRefByValue<const TDesC8> aFmt, ...) |
|
97 { |
|
98 VA_LIST list; |
|
99 VA_START(list, aFmt); |
|
100 #ifdef __FLOGGING__ |
|
101 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
102 #endif |
|
103 TOverflowTruncate8 overflow; |
|
104 TBuf8<KMaxLogLineLength> buf8; |
|
105 buf8.Append(KTracePrefix8); |
|
106 buf8.AppendFormatList(aFmt, list, &overflow); |
|
107 TBuf16<KMaxLogLineLength> buf16(buf8.Length()); |
|
108 buf16.Copy(buf8); |
|
109 TRefByValue<const TDesC> tmpFmt(_L("%S")); |
|
110 RDebug::Print(tmpFmt, &buf16); |
|
111 } |
81 } |
112 #else // no _DEBUG defined |
82 #else // no _DEBUG defined |
113 |
83 |
114 #define LOG( A ) |
84 #define LOG( AAA ) |
115 |
85 |
116 #define LOGGER_ENTERFN( name ) |
86 #define LOGGER_ENTERFN( name ) |
117 #define LOGGER_LEAVEFN( name ) |
87 #define LOGGER_LEAVEFN( name ) |
118 #define LOGGER_WRITE( text ) |
88 #define LOGGER_WRITE( text ) |
119 #define LOGGER_WRITE_1( text,par1 ) |
89 #define LOGGER_WRITE_1( text,par1 ) |
120 #define LOGGER_WRITE_2( text,par1,par2 ) |
90 #define LOGGER_MSG_EC( text,par1 ) |
121 |
|
122 #define TRACE_FUNC_ENTRY |
|
123 #define TRACE_FUNC_EXIT |
|
124 #define TRACE_FUNC |
|
125 |
|
126 |
91 |
127 #endif // _DEBUG |
92 #endif // _DEBUG |
128 |
93 |
129 #endif // __LOGGER_H__ |
94 #endif // __LOGGER_H__ |
130 |
95 |