|
1 /* |
|
2 * Copyright (c) 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 "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 definition |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef PRJ_LOGGING_H |
|
20 #define PRJ_LOGGING_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <bttypes.h> |
|
24 #include "debugconfig.h" |
|
25 |
|
26 #ifdef PRJ_ENABLE_TRACE |
|
27 |
|
28 #ifdef PRJ_FILE_TRACE |
|
29 #include <flogger.h> |
|
30 #else |
|
31 #include <e32debug.h> |
|
32 #endif |
|
33 |
|
34 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow |
|
35 { |
|
36 public: |
|
37 void Overflow(TDes16& /*aDes*/) {} |
|
38 }; |
|
39 |
|
40 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow |
|
41 { |
|
42 public: |
|
43 void Overflow(TDes8& /*aDes*/) {} |
|
44 }; |
|
45 |
|
46 inline void Trace(TRefByValue<const TDesC16> aFmt, ...) |
|
47 { |
|
48 VA_LIST list; |
|
49 VA_START(list,aFmt); |
|
50 #ifdef PRJ_FILE_TRACE |
|
51 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
52 #else |
|
53 TBuf16<KMaxLogLineLength> theFinalString; |
|
54 theFinalString.Append(KTracePrefix16); |
|
55 TOverflowTruncate16 overflow; |
|
56 theFinalString.AppendFormatList(aFmt,list,&overflow); |
|
57 RDebug::Print(theFinalString); |
|
58 #endif |
|
59 } |
|
60 |
|
61 inline void Trace(TRefByValue<const TDesC8> aFmt, ...) |
|
62 { |
|
63 VA_LIST list; |
|
64 VA_START(list, aFmt); |
|
65 #ifdef PRJ_FILE_TRACE |
|
66 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
67 #else |
|
68 TOverflowTruncate8 overflow; |
|
69 TBuf8<KMaxLogLineLength> buf8; |
|
70 buf8.Append(KTracePrefix8); |
|
71 buf8.AppendFormatList(aFmt, list, &overflow); |
|
72 TBuf16<KMaxLogLineLength> buf16(buf8.Length()); |
|
73 buf16.Copy(buf8); |
|
74 TRefByValue<const TDesC> tmpFmt(_L("%S")); |
|
75 RDebug::Print(tmpFmt, &buf16); |
|
76 #endif |
|
77 } |
|
78 |
|
79 inline void TracePanic( |
|
80 char* aFile, |
|
81 TInt aLine, |
|
82 TInt aPanicCode, |
|
83 const TDesC& aPanicCategory) |
|
84 { |
|
85 TPtrC8 fullFileName((const TUint8*)aFile); |
|
86 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
87 TBuf8<KMaxLogLineLength> buf; |
|
88 buf.Append(KPanicPrefix8); |
|
89 buf.AppendFormat(_L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName); |
|
90 Trace(buf); |
|
91 User::Panic(aPanicCategory, aPanicCode); |
|
92 } |
|
93 |
|
94 inline void TraceLeave(char* aFile, TInt aLine, TInt aReason) |
|
95 { |
|
96 TPtrC8 fullFileName((const TUint8*)aFile); |
|
97 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
98 TBuf8<KMaxLogLineLength> buf; |
|
99 buf.Append(KLeavePrefix8); |
|
100 buf.AppendFormat(_L8("%d at line %d in file %S"), aReason, aLine, &fileName); |
|
101 Trace(buf); |
|
102 User::Leave(aReason); |
|
103 } |
|
104 |
|
105 inline void DebugPrintBDAddr(const TBTDevAddr& aAddr) |
|
106 { |
|
107 TBuf<16> addrdes; |
|
108 aAddr.GetReadable(addrdes); |
|
109 Trace(_L("[BTENG]\t BD addr %S") , &addrdes); |
|
110 } |
|
111 |
|
112 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;} |
|
113 |
|
114 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;} |
|
115 |
|
116 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;} |
|
117 |
|
118 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;} |
|
119 |
|
120 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;} |
|
121 |
|
122 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);} |
|
123 |
|
124 #define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory) |
|
125 |
|
126 #define LEAVE_IF_ERROR(REASON) {if (REASON) TraceLeave(__FILE__, __LINE__, REASON);} |
|
127 |
|
128 #define LEAVE_IF_NULL(PTR) {if (!PTR) TraceLeave(__FILE__, __LINE__, KErrGeneral);} |
|
129 |
|
130 #define LEAVE(REASON) {TraceLeave(__FILE__, __LINE__, REASON);} |
|
131 |
|
132 #define TRACE_STATIC_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}} |
|
133 |
|
134 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}} |
|
135 |
|
136 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}} |
|
137 |
|
138 #define TRACE_STATIC_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}} |
|
139 |
|
140 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}} |
|
141 |
|
142 #define RETURN_IF_ERR(ERR) {if(ERR) {TPtrC8 ptr8((TUint8*)__FILE__); Trace(_L8(" RETURN %d at file %S line %d"), ERR, &ptr8, __LINE__); return ERR;}} |
|
143 |
|
144 #define TRACE_BDADDR( a ) { if( KTraceMask & KPRINTINFO ) DebugPrintBDAddr(a); } |
|
145 |
|
146 #else // PRJ_ENABLE_TRACE not defined |
|
147 |
|
148 #define TRACE_INFO(p) |
|
149 |
|
150 #define TRACE_ERROR(p) |
|
151 |
|
152 #define TRACE_STATE(p) |
|
153 |
|
154 #define TRACE_WARNING(p) |
|
155 |
|
156 #define TRACE_INFO_SEG(p) |
|
157 |
|
158 #define TRACE_ASSERT(GUARD, CODE) |
|
159 |
|
160 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);} |
|
161 |
|
162 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));} |
|
163 |
|
164 #define LEAVE_IF_NULL(PTR) {static_cast<void>(User::LeaveIfNull(PTR));} |
|
165 |
|
166 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));} |
|
167 |
|
168 #define TRACE_STATIC_FUNC_ENTRY |
|
169 |
|
170 #define TRACE_FUNC_ENTRY |
|
171 |
|
172 #define TRACE_FUNC_EXIT |
|
173 |
|
174 #define TRACE_STATIC_FUNC |
|
175 |
|
176 #define TRACE_FUNC |
|
177 |
|
178 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;} |
|
179 |
|
180 #define TRACE_BDADDR( a ) |
|
181 |
|
182 #endif // PRJ_ENABLE_TRACE |
|
183 |
|
184 #endif // PRJ_LOGGING_H |