|
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 "debugconfig.h" |
|
23 |
|
24 #ifdef PRJ_ENABLE_TRACE |
|
25 |
|
26 #ifdef PRJ_FILE_TRACE |
|
27 #include <flogger.h> |
|
28 #else |
|
29 #include <e32debug.h> |
|
30 #endif |
|
31 |
|
32 const TInt KMaxLogLineLength = 512; |
|
33 |
|
34 #define KPRINTERROR 0x00000001 // Tracing level: error |
|
35 #define KPRINTINFO 0x00000002 // Tracing level: function trace |
|
36 #define KPRINTSTATE 0x00000004 // Tracing level: state machine info |
|
37 #define KPRINTWARNING 0x00000008 // Tracing level: warning |
|
38 |
|
39 const TInt KTraceMask = KPRINTERROR | KPRINTINFO | KPRINTSTATE | KPRINTWARNING; |
|
40 |
|
41 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow |
|
42 { |
|
43 public: |
|
44 void Overflow(TDes16& /*aDes*/) {} |
|
45 }; |
|
46 |
|
47 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow |
|
48 { |
|
49 public: |
|
50 void Overflow(TDes8& /*aDes*/) {} |
|
51 }; |
|
52 |
|
53 inline void Trace(TRefByValue<const TDesC16> aFmt, ...) |
|
54 { |
|
55 VA_LIST list; |
|
56 VA_START(list,aFmt); |
|
57 #ifdef PRJ_FILE_TRACE |
|
58 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
59 #else |
|
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 inline void Trace(TRefByValue<const TDesC8> aFmt, ...) |
|
69 { |
|
70 VA_LIST list; |
|
71 VA_START(list, aFmt); |
|
72 #ifdef PRJ_FILE_TRACE |
|
73 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
74 #else |
|
75 TOverflowTruncate8 overflow; |
|
76 TBuf8<KMaxLogLineLength> buf8; |
|
77 buf8.Append(KTracePrefix8); |
|
78 buf8.AppendFormatList(aFmt, list, &overflow); |
|
79 TBuf16<KMaxLogLineLength> buf16(buf8.Length()); |
|
80 buf16.Copy(buf8); |
|
81 TRefByValue<const TDesC> tmpFmt(_L("%S")); |
|
82 RDebug::Print(tmpFmt, &buf16); |
|
83 #endif |
|
84 } |
|
85 |
|
86 inline void TracePanic( |
|
87 char* aFile, |
|
88 TInt aLine, |
|
89 TInt aPanicCode, |
|
90 const TDesC& aPanicCategory) |
|
91 { |
|
92 TPtrC8 fullFileName((const TUint8*)aFile); |
|
93 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
94 TBuf8<KMaxLogLineLength> buf; |
|
95 buf.Append(KPanicPrefix8); |
|
96 buf.AppendFormat(_L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName); |
|
97 Trace(buf); |
|
98 User::Panic(aPanicCategory, aPanicCode); |
|
99 } |
|
100 |
|
101 inline void TraceLeave(char* aFile, TInt aLine, TInt aReason) |
|
102 { |
|
103 TPtrC8 fullFileName((const TUint8*)aFile); |
|
104 TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1); |
|
105 TBuf8<KMaxLogLineLength> buf; |
|
106 buf.Append(KLeavePrefix8); |
|
107 buf.AppendFormat(_L8("%d at line %d in file %S"), aReason, aLine, &fileName); |
|
108 Trace(buf); |
|
109 User::LeaveIfError(aReason); |
|
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(REASON) {TraceLeave(__FILE__, __LINE__, REASON);} |
|
129 |
|
130 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}} |
|
131 |
|
132 #define TRACE_FUNC_ENTRY_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}} |
|
133 |
|
134 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}} |
|
135 |
|
136 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}} |
|
137 |
|
138 #define TRACE_FUNC_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}} |
|
139 |
|
140 #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;}} |
|
141 |
|
142 #else // PRJ_ENABLE_TRACE not defined |
|
143 |
|
144 #define TRACE_INFO(p) |
|
145 |
|
146 #define TRACE_ERROR(p) |
|
147 |
|
148 #define TRACE_STATE(p) |
|
149 |
|
150 #define TRACE_WARNING(p) |
|
151 |
|
152 #define TRACE_INFO_SEG(p) |
|
153 |
|
154 #define TRACE_ASSERT(GUARD, CODE) |
|
155 |
|
156 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);} |
|
157 |
|
158 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));} |
|
159 |
|
160 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));} |
|
161 |
|
162 #define TRACE_FUNC_ENTRY |
|
163 |
|
164 #define TRACE_FUNC_ENTRY_THIS |
|
165 |
|
166 #define TRACE_FUNC_EXIT |
|
167 |
|
168 #define TRACE_FUNC |
|
169 |
|
170 #define TRACE_FUNC_THIS |
|
171 |
|
172 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;} |
|
173 #endif // PRJ_ENABLE_TRACE |
|
174 |
|
175 #endif // PRJ_LOGGING_H |