|
1 /* |
|
2 * Copyright (c) 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: trace logs |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __VIMPSTDEBUGTRACE_H__ |
|
19 #define __VIMPSTDEBUGTRACE_H__ |
|
20 |
|
21 // INCLUDES |
|
22 #include "e32std.h" |
|
23 #include <flogger.h> |
|
24 // DEFINES |
|
25 // enable logs printing |
|
26 // into c:\\logs\\vimpst\\vimpst.txt |
|
27 //#define VIMPST_ENABLE_DEBUG_LOGS |
|
28 #undef VIMPST_ENABLE_DEBUG_LOGS |
|
29 |
|
30 /** |
|
31 * Usage of Log MACRO'S |
|
32 * _LIT( KExample, "Example" ); |
|
33 * TXT(s) _L(s) |
|
34 * TRACE( T_LIT("Some text.") ); |
|
35 * TRACE( T_LIT("Some text: %d"), 100 ); |
|
36 * TRACE( T_LIT("Some text: %S"), &KExample ); |
|
37 */ |
|
38 |
|
39 _LIT( KTAdaptDebugOutputDir, "vimpst" ); |
|
40 _LIT( KTAdaptDebugOutputFileName, "vimpst.txt" ); |
|
41 _LIT( KTAdaptDebugOutputDFileName, "dvimpst.txt" ); |
|
42 const TInt KTAdaptMaxLogLineLength = 250 ; |
|
43 #define T_LIT(s) _L(s) |
|
44 #define TRACE TVIMPSTLogger::WriteLog |
|
45 #define TRACED TVIMPSTLogger::DWriteLog // TRACED must be used in details view plugin only |
|
46 #define PLUGIN_UNUSED_PARAM(p) (void) p |
|
47 |
|
48 |
|
49 /** |
|
50 * IM cache debug logger. |
|
51 */ |
|
52 class TVIMPSTLogger |
|
53 { |
|
54 public: //Logging functions |
|
55 /** |
|
56 * WriteLog, write the message into c:\\logs\\vimpst\\vimpst.txt |
|
57 * need to create imcv folder into c:\\logs |
|
58 * @param aFmt, list of messges to print |
|
59 */ |
|
60 static void WriteLog( TRefByValue<const TDesC> aFmt,... ); |
|
61 |
|
62 /** |
|
63 * WriteLog, write the message into c:\\logs\\vimpst\\vimpstd.txt |
|
64 * need to create vimpst folder into c:\\logs |
|
65 * only used for detailsview plugin |
|
66 * @param aFmt, list of messges to print |
|
67 */ |
|
68 static void DWriteLog( TRefByValue<const TDesC> aFmt,... ); |
|
69 |
|
70 private: //Prohibited |
|
71 /** |
|
72 * construtor |
|
73 */ |
|
74 TVIMPSTLogger(); |
|
75 /** |
|
76 * destructor |
|
77 */ |
|
78 ~TVIMPSTLogger(); |
|
79 }; |
|
80 |
|
81 #endif // __VIMPSTDEBUGTRACE_H__ |
|
82 |
|
83 /** |
|
84 * Handler used by logger to truncate the string |
|
85 * rather than panic in case of buffer overflow. |
|
86 */ |
|
87 |
|
88 NONSHARABLE_CLASS ( TAdaptOverflowTruncate ) : public TDes16Overflow |
|
89 { |
|
90 |
|
91 public: |
|
92 void Overflow ( TDes16& /*aDes*/ ) {} |
|
93 }; |
|
94 |
|
95 |
|
96 // ============================ MEMBER FUNCTIONS =============================== |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // TVIMPSTLogger::WriteLog() |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 inline void TVIMPSTLogger::WriteLog ( TRefByValue<const TDesC> aFmt, ... ) |
|
103 { |
|
104 (void) aFmt;//Suppress unused formal parameter warning |
|
105 #ifdef VIMPST_ENABLE_DEBUG_LOGS |
|
106 TBuf< KTAdaptMaxLogLineLength > buffer; |
|
107 buffer.Append ( _L ( "[" ) ); // CSI: 78 # |
|
108 buffer.Append ( RThread().Name() ); |
|
109 buffer.Append ( _L ( "] " ) ); // CSI: 78 # |
|
110 TAdaptOverflowTruncate overflow; |
|
111 VA_LIST list; |
|
112 VA_START ( list, aFmt ); |
|
113 buffer.AppendFormatList ( aFmt, list, &overflow ); |
|
114 RFileLogger logger; |
|
115 if ( logger.Connect() == KErrNone ) |
|
116 { |
|
117 logger.SetDateAndTime ( ETrue, ETrue ); |
|
118 logger.CreateLog ( KTAdaptDebugOutputDir, KTAdaptDebugOutputFileName, |
|
119 EFileLoggingModeAppend ); |
|
120 logger.Write ( buffer ); |
|
121 logger.CloseLog(); |
|
122 logger.Close(); |
|
123 } |
|
124 #endif |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // TVIMPSTLogger::DWriteLog() |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 inline void TVIMPSTLogger::DWriteLog ( TRefByValue<const TDesC> aFmt, ... ) |
|
132 { |
|
133 (void) aFmt;//Suppress unused formal parameter warning |
|
134 #ifdef VIMPST_ENABLE_DEBUG_LOGS |
|
135 TBuf< KTAdaptMaxLogLineLength > buffer; |
|
136 buffer.Append ( _L ( "[" ) ); // CSI: 78 # |
|
137 buffer.Append ( RThread().Name() ); |
|
138 buffer.Append ( _L ( "] " ) ); // CSI: 78 # |
|
139 TAdaptOverflowTruncate overflow; |
|
140 VA_LIST list; |
|
141 VA_START ( list, aFmt ); |
|
142 buffer.AppendFormatList ( aFmt, list, &overflow ); |
|
143 RFileLogger logger; |
|
144 if ( logger.Connect() == KErrNone ) |
|
145 { |
|
146 logger.SetDateAndTime ( ETrue, ETrue ); |
|
147 logger.CreateLog ( KTAdaptDebugOutputDir, KTAdaptDebugOutputDFileName, |
|
148 EFileLoggingModeAppend ); |
|
149 logger.Write ( buffer ); |
|
150 logger.CloseLog(); |
|
151 logger.Close(); |
|
152 } |
|
153 #endif |
|
154 } |
|
155 // End of File |
|
156 |
|
157 |