|
1 /* |
|
2 * Copyright (c) 2005-2008 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: Logging macros used by DS plug-in adapters |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef _LOGGER_H |
|
20 #define _LOGGER_H |
|
21 |
|
22 #ifdef _DEBUG |
|
23 |
|
24 // Define this to enable file logging |
|
25 #define __FLOGGING__ |
|
26 |
|
27 #include <e32svr.h> |
|
28 #ifdef __FLOGGING__ |
|
29 #include <f32file.h> |
|
30 #include <flogger.h> |
|
31 #endif |
|
32 |
|
33 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow |
|
34 { |
|
35 public: |
|
36 void Overflow(TDes16& /*aDes*/) {} |
|
37 }; |
|
38 |
|
39 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow |
|
40 { |
|
41 public: |
|
42 void Overflow(TDes8& /*aDes*/) {} |
|
43 }; |
|
44 |
|
45 _LIT( KLogDir, "BMKDS" ); |
|
46 _LIT( KLogFile, "BookmarkLog.txt" ); |
|
47 |
|
48 #define LOGGER_ENTERFN( name ) {TRACE_FUNC_ENTRY;} |
|
49 #define LOGGER_LEAVEFN( name ) {TRACE_FUNC_EXIT;} |
|
50 |
|
51 _LIT(KTracePrefix16, "[BMKDS] "); |
|
52 _LIT8(KTracePrefix8, "[BMKDS] "); |
|
53 _LIT8(KFuncEntryFormat8, "%S : Begin"); |
|
54 _LIT8(KFuncExitFormat8, "%S : End"); |
|
55 _LIT8(KFuncFormat8, "><%S"); |
|
56 |
|
57 const TInt KMaxLogLineLength = 512; |
|
58 |
|
59 #define LOGGER_WRITE( text ) {_LIT( KTemp, text ); FPrint( KTemp );} |
|
60 #define LOGGER_WRITE_1( text,par1 ) {_LIT( KTemp, text ); FPrint( KTemp, par1 );} |
|
61 #define LOGGER_WRITE8_1( text,par1 ) {_LIT8( KTemp, text ); FPrint( KTemp, par1 );} |
|
62 #define LOGGER_WRITE_2( text,par1,par2 ) {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );} |
|
63 #define LOGGER_WRITE_3( text,par1,par2,par3 ) {_LIT( KTemp, text ); FPrint( KTemp, par1, par2, par3 );} |
|
64 #define LOGGER_WRITE_IFERR_2( text, err ) {if (err) {_LIT( KTemp, text ); FPrint( KTemp, err );}} |
|
65 |
|
66 // New function logging macros |
|
67 #define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);} |
|
68 #define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);} |
|
69 #define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);} |
|
70 |
|
71 // Declare the FPrint function |
|
72 inline void FPrint( TRefByValue<const TDesC16> aFmt, ...) |
|
73 { |
|
74 VA_LIST list; |
|
75 VA_START(list,aFmt); |
|
76 #ifdef __FLOGGING__ |
|
77 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list ); |
|
78 #endif |
|
79 TBuf16<KMaxLogLineLength> theFinalString; |
|
80 theFinalString.Append(KTracePrefix16); |
|
81 TOverflowTruncate16 overflow; |
|
82 theFinalString.AppendFormatList(aFmt,list,&overflow); |
|
83 RDebug::Print(theFinalString); |
|
84 } |
|
85 |
|
86 // Declare the FPrint function |
|
87 inline void FPrint(TRefByValue<const TDesC8> aFmt, ...) |
|
88 { |
|
89 VA_LIST list; |
|
90 VA_START(list, aFmt); |
|
91 #ifdef __FLOGGING__ |
|
92 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
93 #endif |
|
94 TOverflowTruncate8 overflow; |
|
95 TBuf8<KMaxLogLineLength> buf8; |
|
96 buf8.Append(KTracePrefix8); |
|
97 buf8.AppendFormatList(aFmt, list, &overflow); |
|
98 TBuf16<KMaxLogLineLength> buf16(buf8.Length()); |
|
99 buf16.Copy(buf8); |
|
100 TRefByValue<const TDesC> tmpFmt(_L("%S")); |
|
101 RDebug::Print(tmpFmt, &buf16); |
|
102 } |
|
103 #else |
|
104 |
|
105 // No loggings --> reduced code size |
|
106 |
|
107 #define LOGGER_ENTERFN( name ) |
|
108 #define LOGGER_LEAVEFN( name ) |
|
109 #define LOGGER_WRITE( text ) |
|
110 #define LOGGER_WRITE_1( text, par1 ) |
|
111 #define LOGGER_WRITE8_1( text,par1 ) |
|
112 #define LOGGER_WRITE_2( text, par1, par2 ) |
|
113 #define LOGGER_WRITE_3( text, par1, par2, par3 ) |
|
114 #define TRACE_FUNC_ENTRY |
|
115 #define TRACE_FUNC_EXIT |
|
116 #define TRACE_FUNC |
|
117 |
|
118 #endif //_DEBUG |
|
119 |
|
120 #endif // __LOGGER_H__ |
|
121 |
|
122 // End of file |
|
123 |