imstutils/imconversationview/inc/imcvlogger.h
changeset 15 81eeb8c83ce5
parent 0 5e5d6b214f4f
equal deleted inserted replaced
0:5e5d6b214f4f 15:81eeb8c83ce5
     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 #define 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, "imcv" );
       
    42 _LIT( KTAdaptDebugOutputFileName, "imcv.txt" );
       
    43 const TInt KTAdaptMaxLogLineLength = 250 ;
       
    44 #define TXT(s) _L(s)
       
    45 #define IM_CV_LOGS TIMCVLogger::WriteLog
       
    46 #define PLUGIN_UNUSED_PARAM(p) (void) p
       
    47 
       
    48 
       
    49 /**
       
    50  * IM Conversation View logger.
       
    51  */
       
    52 class TIMCVLogger
       
    53     {
       
    54     public: //Logging functions
       
    55     	/*
       
    56         * WriteLog, write the message into c:\\logs\\imcv\\imcv.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         TIMCVLogger();
       
    67         /*
       
    68         * destructor
       
    69         */
       
    70         ~TIMCVLogger();
       
    71     };
       
    72 
       
    73 #endif // IMCVLOGGER_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 // TIMCVLogger::WriteLog()
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 inline void TIMCVLogger::WriteLog ( TRefByValue<const TDesC> aFmt, ... )
       
    97 	{
       
    98 	#ifdef 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 
       
   120 		RDebug::Print( _L("%S"), &buffer );
       
   121 	#endif
       
   122 
       
   123 	}
       
   124 
       
   125 
       
   126 // End of File
       
   127 
       
   128  
       
   129