imstutils/imconversationview/inc/imcvlogger.h
branchRCL_3
changeset 23 9a48e301e94b
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 2007-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 implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef IMCVLOGGER_H
       
    22 #define IMCVLOGGER_H
       
    23 
       
    24 #include <e32svr.h>
       
    25 #include <flogger.h>
       
    26 #include <e32std.h>
       
    27 
       
    28 // enable logs printing
       
    29 // into  c:\\logs\\imcv\\imcv.txt
       
    30 #ifdef __WINS__
       
    31   #ifdef _DEBUG
       
    32     #define ENABLE_DEBUG_LOGS // for WINS UDEB
       
    33  #endif
       
    34 #else
       
    35   #ifdef _DEBUG     
       
    36     #define ENABLE_DEBUG_LOGS // for device UDEB
       
    37   #endif
       
    38 #endif
       
    39 
       
    40 /**   
       
    41 * Usage of Log MACRO'S
       
    42 * _LIT( KExample, "Example" );
       
    43 *  TXT(s) _L(s)	
       
    44 *  IM_CV_LOGS(TXT("Some text.") );
       
    45 *  IM_CV_LOGS(TXT("Some text: %d"), 100 );
       
    46 *  IM_CV_LOGS(TXT("Some text: %S"), &KExample );
       
    47 */
       
    48 
       
    49 _LIT( KTAdaptDebugOutputDir, "imcv" );
       
    50 _LIT( KTAdaptDebugOutputFileName, "imcv.txt" );
       
    51 const TInt KTAdaptMaxLogLineLength = 250 ;
       
    52 #define TXT(s) _L(s)
       
    53 #define IM_CV_LOGS TIMCVLogger::WriteLog
       
    54 #define PLUGIN_UNUSED_PARAM(p) (void) p
       
    55 
       
    56 
       
    57 /**
       
    58  * IM Conversation View logger.
       
    59  */
       
    60 class TIMCVLogger
       
    61     {
       
    62     public: //Logging functions
       
    63     	/*
       
    64         * WriteLog, write the message into c:\\logs\\imcv\\imcv.txt
       
    65         * need to create imcv folder into c:\\logs
       
    66         * @param aFmt, list of messges to print
       
    67         */
       
    68 		static void WriteLog( TRefByValue<const TDesC> aFmt,... );
       
    69 		
       
    70     private: //Prohibited
       
    71     	/*
       
    72         * construtor
       
    73         */
       
    74         TIMCVLogger();
       
    75         /*
       
    76         * destructor
       
    77         */
       
    78         ~TIMCVLogger();
       
    79     };
       
    80 
       
    81 #endif // IMCVLOGGER_H
       
    82 
       
    83 
       
    84 
       
    85 /**
       
    86  * Handler used by logger to truncate the string
       
    87  * rather than panic in case of buffer overflow.
       
    88 */
       
    89 
       
    90 NONSHARABLE_CLASS ( TAdaptOverflowTruncate ) : public TDes16Overflow
       
    91 	{
       
    92 
       
    93 public:
       
    94 	void Overflow ( TDes16& /*aDes*/ ) {}
       
    95 	};
       
    96 
       
    97 
       
    98 // ============================ MEMBER FUNCTIONS ===============================
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // TIMCVLogger::WriteLog()
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 inline void TIMCVLogger::WriteLog ( TRefByValue<const TDesC> aFmt, ... )
       
   105 	{
       
   106 	#ifdef ENABLE_DEBUG_LOGS
       
   107 		( void ) aFmt;//Suppress unused formal parameter warning
       
   108 		TBuf< KTAdaptMaxLogLineLength > buffer;
       
   109 		buffer.Append ( _L ( "[" ) );           // CSI: 78 #
       
   110 		buffer.Append ( RThread().Name() );
       
   111 		buffer.Append ( _L ( "] " ) );          // CSI: 78 #
       
   112 		TAdaptOverflowTruncate overflow;
       
   113 		VA_LIST list;
       
   114 		VA_START ( list, aFmt );
       
   115 		buffer.AppendFormatList ( aFmt, list, &overflow );
       
   116 		RFileLogger logger;
       
   117 
       
   118 		if ( logger.Connect() == KErrNone )
       
   119 			{
       
   120 			logger.SetDateAndTime ( ETrue, ETrue );
       
   121 			logger.CreateLog ( KTAdaptDebugOutputDir, KTAdaptDebugOutputFileName,
       
   122 			                   EFileLoggingModeAppend );
       
   123 			logger.Write ( buffer );
       
   124 			logger.CloseLog();
       
   125 			logger.Close();
       
   126 			}
       
   127 
       
   128 		RDebug::Print( _L("%S"), &buffer );
       
   129 	#endif
       
   130 
       
   131 	}
       
   132 
       
   133 
       
   134 // End of File
       
   135 
       
   136  
       
   137