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