imservices/instantmessagingcache/inc/imcachedebugtrace.h
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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:  logs generation file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __IMCACHEDEBUGTRACE_H__
       
    21 #define __IMCACHEDEBUGTRACE_H__
       
    22 
       
    23 //  INCLUDES
       
    24 #include  "e32std.h"
       
    25 #include <flogger.h>
       
    26 //  DEFINES
       
    27 // enable logs printing
       
    28 // into  c:\\logs\\instantmessagingcache\\instantmessagingcache.txt
       
    29 //#define IMCHACHE_ENABLE_DEBUG_LOGS
       
    30 #undef IMCHACHE_ENABLE_DEBUG_LOGS
       
    31 
       
    32 /**   
       
    33 * Usage of Log MACRO'S
       
    34 * _LIT( KExample, "Example" );
       
    35 *  TXT(s) _L(s)	
       
    36 *  IM_CV_LOGS(TXT("Some text.") );
       
    37 *  IM_CV_LOGS(TXT("Some text: %d"), 100 );
       
    38 *  IM_CV_LOGS(TXT("Some text: %S"), &KExample );
       
    39 */
       
    40 
       
    41 _LIT( KTAdaptDebugOutputDir, "imcache" );
       
    42 _LIT( KTAdaptDebugOutputFileName, "imcache.txt" );
       
    43 const TInt KTAdaptMaxLogLineLength = 250 ;
       
    44 #define T_LIT(s) _L(s)
       
    45 #define TRACE TIMChacheLogger::WriteLog
       
    46 #define PLUGIN_UNUSED_PARAM(p) (void) p
       
    47 
       
    48 
       
    49 /**
       
    50  * IM cache debug logger.
       
    51  */
       
    52 class TIMChacheLogger
       
    53     {
       
    54     public: //Logging functions
       
    55     	/**
       
    56         * WriteLog, write the message into c:\\logs\\instantmessagingcache\\instantmessagingcache.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     private: //Prohibited
       
    63     	/**
       
    64         * construtor
       
    65         */
       
    66         TIMChacheLogger();
       
    67         /**
       
    68         * destructor
       
    69         */
       
    70         ~TIMChacheLogger();
       
    71     };
       
    72 
       
    73 #endif // __IMCACHEDEBUGTRACE_H__
       
    74 
       
    75 
       
    76 
       
    77 /**
       
    78  * Handler used by logger to truncate the string
       
    79  * rather than panic in case of buffer overflow.
       
    80 */
       
    81 
       
    82 NONSHARABLE_CLASS ( TAdaptOverflowTruncate ) : public TDes16Overflow
       
    83 	{
       
    84 
       
    85 public:
       
    86 	void Overflow ( TDes16& /*aDes*/ ) {}
       
    87 	};
       
    88 
       
    89 
       
    90 // ============================ MEMBER FUNCTIONS ===============================
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // TIMChacheLogger::WriteLog()
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 inline void TIMChacheLogger::WriteLog ( TRefByValue<const TDesC> aFmt, ... )
       
    97 	{
       
    98 	#ifdef IMCHACHE_ENABLE_DEBUG_LOGS
       
    99 		( void ) aFmt;//Suppress unused formal parameter warning
       
   100 		TBuf< KTAdaptMaxLogLineLength > buffer;
       
   101 		buffer.Append ( _L ( "[" ) );           // CSI: 78 #
       
   102 		buffer.Append ( RThread().Name() );
       
   103 		buffer.Append ( _L ( "] " ) );          // CSI: 78 #
       
   104 		TAdaptOverflowTruncate overflow;
       
   105 		VA_LIST list;
       
   106 		VA_START ( list, aFmt );
       
   107 		buffer.AppendFormatList ( aFmt, list, &overflow );
       
   108 		RFileLogger logger;
       
   109 
       
   110 		if ( logger.Connect() == KErrNone )
       
   111 			{
       
   112 			logger.SetDateAndTime ( ETrue, ETrue );
       
   113 			logger.CreateLog ( KTAdaptDebugOutputDir, KTAdaptDebugOutputFileName,
       
   114 			                   EFileLoggingModeAppend );
       
   115 			logger.Write ( buffer );
       
   116 			logger.CloseLog();
       
   117 			logger.Close();
       
   118 			}
       
   119 	#endif
       
   120 
       
   121 	}
       
   122 
       
   123 
       
   124 // End of File
       
   125 
       
   126