|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #ifndef __SWI_LOG_H__ |
|
18 #define __SWI_LOG_H__ |
|
19 |
|
20 #include <e32debug.h> |
|
21 namespace DSD |
|
22 { |
|
23 |
|
24 #ifdef _DEBUG |
|
25 |
|
26 //#define _OMXIL_COMMON_DEBUG_TRACING_ON |
|
27 #ifdef _OMXIL_COMMON_DEBUG_TRACING_ON |
|
28 |
|
29 |
|
30 |
|
31 class TTruncateOverflowHandler16 : public TDes16Overflow |
|
32 { |
|
33 public: |
|
34 virtual void Overflow( TDes16& aDes ); |
|
35 }; |
|
36 |
|
37 inline void TTruncateOverflowHandler16::Overflow( TDes16& aDes) |
|
38 { |
|
39 _LIT(KErrOverflowMsg,"Descriptor Overflow, hence value truncated"); |
|
40 if( aDes.MaxLength() >= KErrOverflowMsg().Length() + aDes.Length() ) |
|
41 aDes.Append(KErrOverflowMsg); |
|
42 } |
|
43 |
|
44 class TTruncateOverflowHandler8 : public TDes8Overflow |
|
45 { |
|
46 public: |
|
47 virtual void Overflow( TDes8& aDes ); |
|
48 }; |
|
49 |
|
50 inline void TTruncateOverflowHandler8::Overflow( TDes8& aDes) |
|
51 { |
|
52 _LIT(KErrOverflowMsg,"Descriptor Overflow, hence value truncated"); |
|
53 if( aDes.MaxLength() >= KErrOverflowMsg().Length() + aDes.Length() ) |
|
54 aDes.Append(KErrOverflowMsg); |
|
55 } |
|
56 |
|
57 #define DEBUG_PRINTF(a) {DSD::DebugPrintf(__LINE__, __FILE__, a);} |
|
58 #define DEBUG_PRINTF2(a, b) {DSD::DebugPrintf(__LINE__, __FILE__, a, b);} |
|
59 #define DEBUG_PRINTF3(a, b, c) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c);} |
|
60 #define DEBUG_PRINTF4(a, b, c, d) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c, d);} |
|
61 #define DEBUG_PRINTF5(a, b, c, d, e) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);} |
|
62 |
|
63 #define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) |
|
64 |
|
65 // UTF-8 overload of the DebufPrintf method. Should be used by default, |
|
66 // since it's cheaper both in CPU cycles and stack space. |
|
67 |
|
68 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC8> aFormat, ...) |
|
69 { |
|
70 TTruncateOverflowHandler8 overflowHandler8; |
|
71 VA_LIST list; |
|
72 VA_START(list, aFormat); |
|
73 |
|
74 TTime now; |
|
75 now.HomeTime(); |
|
76 |
|
77 TBuf8<1024> buffer; |
|
78 _LIT8(KSwiLogPrefix, "[ccommon] "); |
|
79 _LIT8(KSwiLineFileFormat, "TID[%d] : [%s:%d] -- "); |
|
80 buffer.Append(KSwiLogPrefix); |
|
81 RThread thread; |
|
82 TUint threadId = thread.Id(); |
|
83 thread.Close(); |
|
84 RProcess proc; |
|
85 TFileName fName = proc.FileName(); |
|
86 proc.Close(); |
|
87 buffer.AppendFormat(KSwiLineFileFormat, threadId, aFile, aLine); |
|
88 buffer.AppendFormatList(aFormat, list ,&overflowHandler8 ); |
|
89 buffer.Append(_L8("\r\n")); |
|
90 |
|
91 RDebug::RawPrint(buffer); |
|
92 |
|
93 VA_END(list); |
|
94 } |
|
95 |
|
96 // Unicode DebufPrintf overload |
|
97 |
|
98 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC16> aFormat, ...) |
|
99 { |
|
100 TTruncateOverflowHandler16 overflowHandler16; |
|
101 VA_LIST list; |
|
102 VA_START(list, aFormat); |
|
103 |
|
104 TTime now; |
|
105 now.HomeTime(); |
|
106 |
|
107 TBuf8<256> header; |
|
108 _LIT8(KSwiLogPrefix, "[common] "); |
|
109 _LIT8(KSwiLineFileFormat, "%Ld Line: % 5d, File: %s -- "); |
|
110 header.Append(KSwiLogPrefix); |
|
111 header.AppendFormat(KSwiLineFileFormat, now.Int64(), aLine, aFile); |
|
112 |
|
113 TBuf<1024> buffer; |
|
114 buffer.Copy(header); |
|
115 buffer.AppendFormatList(aFormat, list ,&overflowHandler16); |
|
116 buffer.Append(_L("\r\n")); |
|
117 |
|
118 RDebug::RawPrint(buffer); |
|
119 |
|
120 VA_END(list); |
|
121 } |
|
122 #else |
|
123 |
|
124 #define DEBUG_PRINTF(a) |
|
125 #define DEBUG_PRINTF2(a, b) |
|
126 #define DEBUG_PRINTF3(a, b, c) |
|
127 #define DEBUG_PRINTF4(a, b, c, d) |
|
128 #define DEBUG_PRINTF5(a, b, c, d, e) |
|
129 |
|
130 #define DEBUG_CODE_SECTION(a) |
|
131 |
|
132 #endif |
|
133 |
|
134 #else |
|
135 |
|
136 #define DEBUG_PRINTF(a) |
|
137 #define DEBUG_PRINTF2(a, b) |
|
138 #define DEBUG_PRINTF3(a, b, c) |
|
139 #define DEBUG_PRINTF4(a, b, c, d) |
|
140 #define DEBUG_PRINTF5(a, b, c, d, e) |
|
141 |
|
142 #define DEBUG_CODE_SECTION(a) |
|
143 |
|
144 #endif |
|
145 |
|
146 |
|
147 } // namespace DSD |
|
148 |
|
149 #endif // __SWI_LOG_H__ |