Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #ifndef FEATMGRDEBUG_H
21 #define FEATMGRDEBUG_H
27 // Enable macros to support error and/or info logging
29 //#define FEATMGR_INFO_LOG_ENABLED
30 //#define FEATMGR_ERROR_LOG_ENABLED
31 #define FEATMGR_TIMESTAMP_ENABLED
36 * Prefix trace macro to complete tracing with component name.
37 * Returns TDesC which can be used directly with RDebug or RFileLogger.
39 #define PREFIX( aMsg ) TPtrC( (const TText*)L"[EFM]: " L##aMsg )
44 #define ERROR_PREFIX( aMsg ) PREFIX( "[ERROR]: " L##aMsg )
47 * Prefix macro for strings
49 #define _PREFIX_CHAR( aMsg ) (const char*)"[EFM]: " ##aMsg
52 #ifdef FEATMGR_INFO_LOG_ENABLED
54 #define INFO_LOG( aMsg ) { RDebug::Print( PREFIX( aMsg ) ); }
56 #define INFO_LOG1( aMsg, aArg1 )\
57 { RDebug::Print( PREFIX( aMsg ), aArg1 ); }
59 #define INFO_LOG2( aMsg, aArg1, aArg2 )\
60 { RDebug::Print( PREFIX( aMsg ), aArg1, aArg2 ); }
62 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\
63 { RDebug::Print( PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
65 #define FUNC( aMsg, aP1 )\
67 RDebug::Printf( aMsg, aP1 );\
69 // Function log object
70 _LIT8( KFuncNameTerminator, "(" );
71 _LIT8( KFuncLeavePattern, "L" );
77 static void Cleanup( TAny* aPtr )
79 TFuncLog* self = static_cast< TFuncLog* >( aPtr );
81 FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected
84 inline TFuncLog( const char* aFunc ) :
85 iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
87 iCleanupItem( Cleanup, this ),
90 TInt pos( iFunc.Find( KFuncNameTerminator ) );
91 if( pos != KErrNotFound )
93 iFunc.Set( iFunc.Left( pos ) );
94 iCanLeave = !iFunc.Right( KFuncLeavePattern().Length() ).Compare( KFuncLeavePattern );
97 CleanupStack::PushL( iCleanupItem ); // Ignore warnings
100 FUNC( _PREFIX_CHAR("%S-START"), &iFunc );
109 CleanupStack::Pop( this ); // Pop the cleanup item
111 FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished
119 TCleanupItem iCleanupItem;
123 #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
125 #else // FEATMGR_INFO_LOG_ENABLED
127 #define INFO_LOG( aMsg )
129 #define INFO_LOG1( aMsg, aArg1 )
131 #define INFO_LOG2( aMsg, aArg1, aArg2 )
133 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )
137 #endif // FEATMGR_INFO_LOG_ENABLED
140 #ifdef FEATMGR_TIMESTAMP_ENABLED
142 #define TIMESTAMP( aCaption )\
146 TDateTime dt = t.DateTime();\
147 _LIT( KCaption, aCaption );\
148 RDebug::Print( PREFIX("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
149 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
154 #define TIMESTAMP( aCaption )
156 #endif // FEATMGR_TIMESTAMP_ENABLED
159 #ifdef FEATMGR_ERROR_LOG_ENABLED
161 #define ERROR_LOG( aMsg )\
162 {RDebug::Print( ERROR_PREFIX( aMsg ) ); }
164 #define ERROR_LOG1( aMsg, aArg1 )\
165 {RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
167 #define ERROR_LOG2( aMsg, aArg1, aArg2 )\
168 { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
170 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\
171 { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
173 #define LOG_IF_ERROR( aErr, aMsg )\
174 if ( ( aErr ) != KErrNone )\
175 { RDebug::Print( ERROR_PREFIX( aMsg )); }
177 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\
178 if ( ( aErr ) != KErrNone )\
179 { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
181 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\
182 if ( ( aErr ) != KErrNone )\
183 { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
185 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\
186 if ( ( aErr ) != KErrNone )\
187 { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
189 #else // FEATMGR_ERROR_LOG_ENABLED
191 #define ERROR_LOG( aMsg )
193 #define ERROR_LOG1( aMsg, aArg1 )
195 #define ERROR_LOG2( aMsg, aArg1, aArg2 )
197 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )
199 // Remove compiler warning
200 #define LOG_IF_ERROR( aErr, aMsg ) ( aErr ) = ( aErr );
202 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 ) ( aErr ) = ( aErr );
204 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 ) ( aErr ) = ( aErr );
206 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) ( aErr ) = ( aErr );
208 #endif // FEATMGR_ERROR_LOG_ENABLED
211 #endif // FEATMGRDEBUG_H