servicewidget/inc/swpdebugtrace.h
branchRCL_3
changeset 28 3104fc151679
parent 27 2b7283837edb
child 29 9a48e301e94b
equal deleted inserted replaced
27:2b7283837edb 28:3104fc151679
     1 /*
       
     2 * Copyright (c) 2008 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:  logger 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __SWPDEBUGTRACE_H__
       
    21 #define __SWPDEBUGTRACE_H__
       
    22 
       
    23 //  INCLUDES
       
    24 #include  "e32std.h"
       
    25 #include <flogger.h>
       
    26 //  DEFINES
       
    27 // enable logs printing
       
    28 // into  c:\\logs\\swp\\swp.txt
       
    29 #ifdef __WINS__
       
    30  #ifdef _DEBUG
       
    31     #define SWP_ENABLE_DEBUG_LOGS // for WINS UDEB
       
    32  #endif
       
    33 #else
       
    34  #ifdef _DEBUG
       
    35     #define SWP_ENABLE_DEBUG_LOGS // for device UDEB
       
    36  #endif
       
    37 #endif
       
    38 
       
    39 /**   
       
    40 * Usage of Log MACRO'S
       
    41 * _LIT( KExample, "Example" );
       
    42 *  TXT(s) _L(s)	
       
    43 *  TRACE_SWP(TXT("Some text.") );
       
    44 *  TRACE_SWP(TXT("Some text: %d"), 100 );
       
    45 *  TRACE_SWP(TXT("Some text: %S"), &KExample );
       
    46 */
       
    47 
       
    48 _LIT( KTAdaptDebugOutputDir, "swp" );
       
    49 _LIT( KTAdaptDebugOutputFileName, "swp.txt" );
       
    50 const TInt KTAdaptMaxLogLineLength = 250 ;
       
    51 #define TXT(s) _L(s)
       
    52 #define TRACE_SWP TSWPLogger::WriteLog
       
    53 #define PLUGIN_UNUSED_PARAM(p) (void) p
       
    54 
       
    55 
       
    56 /**
       
    57  * IM cache debug logger.
       
    58  */
       
    59 class TSWPLogger
       
    60     {
       
    61     public: //Logging functions
       
    62     	/**
       
    63         * WriteLog, write the message into c:\\logs\\swp\\swp.txt
       
    64         * @param aFmt, list of messges to print
       
    65         */
       
    66 		static void WriteLog( TRefByValue<const TDesC> aFmt,... );
       
    67 		
       
    68     private: //Prohibited
       
    69     	/**
       
    70         * construtor
       
    71         */
       
    72         TSWPLogger();
       
    73         /**
       
    74         * destructor
       
    75         */
       
    76         ~TSWPLogger();
       
    77     };
       
    78 
       
    79 #endif // __SWPDEBUGTRACE_H__
       
    80 
       
    81 
       
    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 // TSWPLogger::WriteLog()
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 inline void TSWPLogger::WriteLog ( TRefByValue<const TDesC> aFmt, ... )
       
   103 	{
       
   104 	#ifdef SWP_ENABLE_DEBUG_LOGS
       
   105 		( void ) aFmt;//Suppress unused formal parameter warning
       
   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 
       
   116 		if ( logger.Connect() == KErrNone )
       
   117 			{
       
   118 			logger.SetDateAndTime ( ETrue, ETrue );
       
   119 			logger.CreateLog ( KTAdaptDebugOutputDir, KTAdaptDebugOutputFileName,
       
   120 			                   EFileLoggingModeAppend );
       
   121 			logger.Write ( buffer );
       
   122 			logger.CloseLog();
       
   123 			logger.Close();
       
   124 			}
       
   125 	#endif
       
   126 
       
   127 	}
       
   128 
       
   129 
       
   130 // End of File
       
   131 
       
   132