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