1 // Copyright (c) 2005-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 // All rights reserved. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 |
|
24 #ifndef LOGGER_H |
|
25 #define LOGGER_H |
|
26 |
|
27 #include <e32base.h> |
|
28 |
|
29 // Control function entry and exit logging using a compile-time switch. |
|
30 //#define __LOG_FUNCTIONS__ |
|
31 |
|
32 // Dump contents of packets using a compile-time switch. |
|
33 //#define __LOG_PACKET_DUMP__ |
|
34 |
|
35 class TFunctionLogger; |
|
36 |
|
37 #ifndef __COMMSDEBUGUTILITY_H__ // comms-infras/commsdebugutility.h not included |
|
38 #ifdef _DEBUG // If this is a debug build... |
|
39 // Set flogging active. |
|
40 #define __FLOG_ACTIVE |
|
41 #endif |
|
42 #endif |
|
43 |
|
44 #ifdef __FLOG_ACTIVE |
|
45 #define IF_FLOGGING(a) a |
|
46 #else |
|
47 #define IF_FLOGGING(a) |
|
48 #endif |
|
49 |
|
50 _LIT8(KDefaultLogFile, "obex"); |
|
51 |
|
52 #ifdef __FLOG_ACTIVE |
|
53 #define LEAVEIFERRORL(a) VerboseLeaveIfErrorL(KLogComponent, __FILE__, __LINE__, a) |
|
54 #define PANIC(CAT, CODE) VerbosePanic(KLogComponent, __FILE__, __LINE__, CODE, (TText8*)#CODE, CAT) |
|
55 #define FLOG(a) CObexLog::Write(KDefaultLogFile, a); |
|
56 |
|
57 #define FTRACE(a) {a;} |
|
58 #define LOG(text) CObexLog::Write(KLogComponent, text); |
|
59 #define LOG1(text, a) CObexLog::WriteFormat(KLogComponent, text, a); |
|
60 #define LOG2(text, a, b) CObexLog::WriteFormat(KLogComponent, text, a, b); |
|
61 #define LOG3(text, a, b, c) CObexLog::WriteFormat(KLogComponent, text, a, b, c); |
|
62 #define LOGHEXDESC(desc) CObexLog::HexDump(KLogComponent, 0, 0, desc.Ptr() , desc.Length()); |
|
63 #define LOGHEXRAW(data, len) CObexLog::HexDump(KLogComponent, 0, 0, data, len); |
|
64 #else |
|
65 #define LEAVEIFERRORL(a) static_cast<void>(User::LeaveIfError(a)) |
|
66 #define PANIC(CAT, CODE) User::Panic(CAT, CODE) |
|
67 #define FLOG(a) |
|
68 #define FTRACE(a) |
|
69 #define LOG(text) |
|
70 #define LOG1(text, a) |
|
71 #define LOG2(text, a, b) |
|
72 #define LOG3(text, a, b, c) |
|
73 #define LOGHEXDESC(desc) |
|
74 #define LOGHEXRAW(data, len) |
|
75 #endif // __FLOG_ACTIVE |
|
76 |
|
77 #define FORCED_LOG_FUNC TFunctionLogger __instrument(KLogComponent, TPtrC8((TUint8*)__PRETTY_FUNCTION__), (TAny*)this); |
|
78 #define FORCED_LOG_STATIC_FUNC_ENTRY TFunctionLogger __instrument(KLogComponent, TPtrC8((TUint8*)__PRETTY_FUNCTION__), (TAny*)NULL); |
|
79 |
|
80 #if ( defined __FLOG_ACTIVE && defined __LOG_FUNCTIONS__ ) |
|
81 #define LOG_LINE CObexLog::Write(KLogComponent, KNullDesC8()); |
|
82 #define LOG_FUNC FORCED_LOG_FUNC |
|
83 #define LOG_STATIC_FUNC_ENTRY FORCED_LOG_STATIC_FUNC_ENTRY |
|
84 #else |
|
85 #define LOG_LINE |
|
86 #define LOG_FUNC |
|
87 #define LOG_STATIC_FUNC_ENTRY |
|
88 #endif |
|
89 |
|
90 |
|
91 |
|
92 NONSHARABLE_CLASS(CObexLog) : public CBase |
|
93 { |
|
94 public: |
|
95 IMPORT_C static TInt Connect(); |
|
96 IMPORT_C static void Close(); |
|
97 |
|
98 IMPORT_C static void Write(const TDesC8& aCmpt, const TDesC8& aText); |
|
99 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC8> aFmt, ...); |
|
100 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC8> aFmt, VA_LIST& aList); |
|
101 IMPORT_C static void Write(const TDesC8& aCmpt, const TDesC16& aText); |
|
102 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC16> aFmt, ...); |
|
103 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC16> aFmt, VA_LIST& aList); |
|
104 IMPORT_C static void HexDump(const TDesC8& aCmpt, const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen); |
|
105 }; |
|
106 |
|
107 |
|
108 #ifndef NO_FPRINT |
|
109 inline void FPrint(const TRefByValue<const TDesC> IF_FLOGGING(aFmt), ...) |
|
110 { |
|
111 #ifdef __FLOG_ACTIVE |
|
112 VA_LIST list; |
|
113 VA_START(list,aFmt); |
|
114 CObexLog::WriteFormat(KDefaultLogFile, aFmt, list); |
|
115 #endif |
|
116 } |
|
117 #endif |
|
118 |
|
119 |
|
120 #ifndef NO_FHEX_PTR |
|
121 inline void FHex(const TUint8* IF_FLOGGING(aPtr), TInt IF_FLOGGING(aLen)) |
|
122 { |
|
123 #ifdef __FLOG_ACTIVE |
|
124 CObexLog::HexDump(KDefaultLogFile, 0, 0, aPtr, aLen); |
|
125 #endif |
|
126 } |
|
127 #endif |
|
128 |
|
129 |
|
130 #ifndef NO_FHEX_DESC |
|
131 inline void FHex(const TDesC8& IF_FLOGGING(aDes)) |
|
132 { |
|
133 #ifdef __FLOG_ACTIVE |
|
134 FHex(aDes.Ptr(), aDes.Length()); |
|
135 #endif |
|
136 } |
|
137 #endif |
|
138 |
|
139 |
|
140 IMPORT_C void VerboseLeaveIfErrorL(const TDesC8& aCpt, |
|
141 char* aFile, |
|
142 TInt aLine, |
|
143 TInt aReason); |
|
144 |
|
145 IMPORT_C void VerbosePanic(const TDesC8& aCpt, |
|
146 char* aFile, |
|
147 TInt aLine, |
|
148 TInt aPanicCode, |
|
149 TText8* aPanicName, |
|
150 const TDesC& aPanicCategory); |
|
151 |
|
152 NONSHARABLE_CLASS(TFunctionLogger) |
|
153 { |
|
154 public: |
|
155 IMPORT_C TFunctionLogger(const TDesC8& aCpt, const TDesC8& aString, TAny* aThis); |
|
156 IMPORT_C ~TFunctionLogger(); |
|
157 |
|
158 private: |
|
159 TPtrC8 iCpt; |
|
160 TPtrC8 iString; |
|
161 }; |
|
162 |
|
163 #endif // LOGGER_H |
|