servicewidget/inc/swpdebugtrace.h
changeset 15 81eeb8c83ce5
parent 0 5e5d6b214f4f
equal deleted inserted replaced
0:5e5d6b214f4f 15:81eeb8c83ce5
     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 #define SWP_ENABLE_DEBUG_LOGS
       
    30 
       
    31 /**   
       
    32 * Usage of Log MACRO'S
       
    33 * _LIT( KExample, "Example" );
       
    34 *  TXT(s) _L(s)	
       
    35 *  TRACE_SWP(TXT("Some text.") );
       
    36 *  TRACE_SWP(TXT("Some text: %d"), 100 );
       
    37 *  TRACE_SWP(TXT("Some text: %S"), &KExample );
       
    38 */
       
    39 
       
    40 _LIT( KTAdaptDebugOutputDir, "swp" );
       
    41 _LIT( KTAdaptDebugOutputFileName, "swp.txt" );
       
    42 const TInt KTAdaptMaxLogLineLength = 250 ;
       
    43 #define TXT(s) _L(s)
       
    44 #define TRACE_SWP TSWPLogger::WriteLog
       
    45 #define PLUGIN_UNUSED_PARAM(p) (void) p
       
    46 
       
    47 
       
    48 /**
       
    49  * IM cache debug logger.
       
    50  */
       
    51 class TSWPLogger
       
    52     {
       
    53     public: //Logging functions
       
    54     	/**
       
    55         * WriteLog, write the message into c:\\logs\\swp\\swp.txt
       
    56         * @param aFmt, list of messges to print
       
    57         */
       
    58 		static void WriteLog( TRefByValue<const TDesC> aFmt,... );
       
    59 		
       
    60     private: //Prohibited
       
    61     	/**
       
    62         * construtor
       
    63         */
       
    64         TSWPLogger();
       
    65         /**
       
    66         * destructor
       
    67         */
       
    68         ~TSWPLogger();
       
    69     };
       
    70 
       
    71 #endif // __SWPDEBUGTRACE_H__
       
    72 
       
    73 
       
    74 
       
    75 /**
       
    76  * Handler used by logger to truncate the string
       
    77  * rather than panic in case of buffer overflow.
       
    78 */
       
    79 
       
    80 NONSHARABLE_CLASS ( TAdaptOverflowTruncate ) : public TDes16Overflow
       
    81 	{
       
    82 
       
    83 public:
       
    84 	void Overflow ( TDes16& /*aDes*/ ) {}
       
    85 	};
       
    86 
       
    87 
       
    88 // ============================ MEMBER FUNCTIONS ===============================
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // TSWPLogger::WriteLog()
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 inline void TSWPLogger::WriteLog ( TRefByValue<const TDesC> aFmt, ... )
       
    95 	{
       
    96 	#ifdef SWP_ENABLE_DEBUG_LOGS
       
    97 		( void ) aFmt;//Suppress unused formal parameter warning
       
    98 		TBuf< KTAdaptMaxLogLineLength > buffer;
       
    99 		buffer.Append ( _L ( "[" ) );           // CSI: 78 #
       
   100 		buffer.Append ( RThread().Name() );
       
   101 		buffer.Append ( _L ( "] " ) );          // CSI: 78 #
       
   102 		TAdaptOverflowTruncate overflow;
       
   103 		VA_LIST list;
       
   104 		VA_START ( list, aFmt );
       
   105 		buffer.AppendFormatList ( aFmt, list, &overflow );
       
   106 		RFileLogger logger;
       
   107 
       
   108 		if ( logger.Connect() == KErrNone )
       
   109 			{
       
   110 			logger.SetDateAndTime ( ETrue, ETrue );
       
   111 			logger.CreateLog ( KTAdaptDebugOutputDir, KTAdaptDebugOutputFileName,
       
   112 			                   EFileLoggingModeAppend );
       
   113 			logger.Write ( buffer );
       
   114 			logger.CloseLog();
       
   115 			logger.Close();
       
   116 			}
       
   117 	#endif
       
   118 
       
   119 	}
       
   120 
       
   121 
       
   122 // End of File
       
   123 
       
   124