|
1 /* |
|
2 * Copyright (c) 2007 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: Debug printing to a log file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_BSDEBUG_H |
|
20 #define C_BSDEBUG_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32std.h> |
|
24 |
|
25 #ifdef _DEBUG |
|
26 #include <flogger.h> |
|
27 #include "bsmydebug.h" |
|
28 |
|
29 // Take care that the correct adatmydebug.h will be included |
|
30 // In adatmydebug.h in your module inc directory, |
|
31 // define your application-specific configuration like this: |
|
32 // ---------------------------------------------------------- |
|
33 // Debug file - debug output is disabled if the parent dir does not exist |
|
34 // _LIT(KDebugFileName, "C:\\logs\\bs\\bsengine.txt" ); |
|
35 |
|
36 // Replace the current debug file - if not defined appends to the file |
|
37 #ifndef APPEND_TO_DEBUG_FILE |
|
38 #define REPLACE_DEBUG_FILE |
|
39 #endif |
|
40 |
|
41 // Maximum formatted size resulting from a single DEBUG* call |
|
42 #ifndef MAX_DEBUG_STRING_LENGTH |
|
43 #define MAX_DEBUG_STRING_LENGTH 4096 |
|
44 #endif |
|
45 // ---------------------------------------------------------- |
|
46 |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 static void DoOutput( TDesC8& aData ); |
|
50 |
|
51 static void DebugStringNarrowL( const char* aFmt, ... ) |
|
52 { |
|
53 VA_LIST args; |
|
54 VA_START(args, aFmt); |
|
55 |
|
56 TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt)); |
|
57 HBufC8* buf = HBufC8::NewLC( MAX_DEBUG_STRING_LENGTH ); |
|
58 buf->Des().FormatList( fmt, args ); |
|
59 buf->Des().Append( '\n' ); |
|
60 DoOutput( *buf ); |
|
61 CleanupStack::PopAndDestroy( buf ); // buf |
|
62 |
|
63 VA_END(args); |
|
64 } |
|
65 |
|
66 static void DebugStringWideL( const char* aFmt, ... ) |
|
67 { |
|
68 VA_LIST args; |
|
69 VA_START(args, aFmt); |
|
70 |
|
71 TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt)); |
|
72 HBufC* fmt16 = HBufC::NewLC( fmt.Length( ) ); |
|
73 fmt16->Des().Copy( fmt ); |
|
74 HBufC* buf = HBufC::NewLC( MAX_DEBUG_STRING_LENGTH ); |
|
75 buf->Des().FormatList( *fmt16, args ); |
|
76 buf->Des().Append( '\n' ); |
|
77 HBufC8* buf8 = HBufC8::NewLC( buf->Length( ) ); |
|
78 buf8->Des().Copy( *buf ); |
|
79 DoOutput( *buf8 ); |
|
80 CleanupStack::PopAndDestroy( 3 ); // fmt16, buf, buf8 |
|
81 |
|
82 VA_END(args); |
|
83 } |
|
84 |
|
85 static void DebugBufferL( const TDesC8& aBuf ) |
|
86 { |
|
87 DebugStringNarrowL( "\"%S\"", &aBuf ); |
|
88 } |
|
89 |
|
90 static void DebugBufferL( const TDesC& aBuf ) |
|
91 { |
|
92 DebugStringWideL( "\"%S\"", &aBuf ); |
|
93 } |
|
94 |
|
95 static void DebugTimeL( const TTime& aTime ) |
|
96 { |
|
97 TBuf<64> dateTimeString; |
|
98 _LIT(KDateString, "%E%D%X%N%Y %1 %2 %3" ); |
|
99 aTime.FormatL( dateTimeString, KDateString ); |
|
100 DebugBufferL( dateTimeString ); |
|
101 _LIT(KTimeString, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B" ); |
|
102 aTime.FormatL( dateTimeString, KTimeString ); |
|
103 DebugBufferL( dateTimeString ); |
|
104 } |
|
105 |
|
106 static void DoOutput( TDesC8& aData ) |
|
107 { |
|
108 RFileLogger::Write( KDebugDirName, KDebugFileName, |
|
109 EFileLoggingModeAppend, aData ); |
|
110 } |
|
111 #endif |
|
112 |
|
113 // MACROS |
|
114 // If you output one or more narrow descriptors by using '%S', |
|
115 // use DEBUGSTRING8 |
|
116 // else if you output one or more unicode descriptors by using '%S', |
|
117 // use DEBUGSTRING16 |
|
118 // else |
|
119 // use DEBUGSTRING |
|
120 // |
|
121 // Narrow and unicode cannot be mixed in a single DEBUGSTRINGx call. |
|
122 |
|
123 #ifdef _DEBUG |
|
124 #define DEBUGINIT() DebugInit() |
|
125 #define DEBUGINITSUSPENDED() DebugInit(ETrue) |
|
126 #define DEBUGENABLE() SetDebugEnabled(ETrue) |
|
127 #define DEBUGDISABLE() SetDebugEnabled(EFalse) |
|
128 #define DEBUGSUSPEND() SetDebugSuspended(ETrue) |
|
129 #define DEBUGCONTINUE() SetDebugSuspended(EFalse) |
|
130 #define DEBUG(x) DebugStringNarrowL x |
|
131 #define DEBUG8(x) DebugStringNarrowL x |
|
132 #define DEBUG16(x) DebugStringWideL x |
|
133 #define DEBUGBUFFER(x) DebugBufferL x |
|
134 #define DEBUGTIME(x) DebugTimeL x |
|
135 #else |
|
136 #define DEBUGINIT() |
|
137 #define DEBUGINITSUSPENDED() |
|
138 #define DEBUGENABLE() |
|
139 #define DEBUGDISABLE() |
|
140 #define DEBUGSUSPEND() |
|
141 #define DEBUGCONTINUE() |
|
142 #define DEBUG(x) |
|
143 #define DEBUG8(x) |
|
144 #define DEBUG16(x) |
|
145 #define DEBUGBUFFER(x) |
|
146 #define DEBUGTIME(x) |
|
147 #endif |
|
148 |
|
149 #endif // C_BSDEBUG_H |