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