ImagePrint/ImagePrintEngine/DeviceProtocols/xhtmlfilecomposer/inc/cxfclogger.h
branchGCC_SURGE
changeset 25 59ea2209bb67
parent 23 08cc4cc059d4
parent 15 a92d00fca574
equal deleted inserted replaced
23:08cc4cc059d4 25:59ea2209bb67
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Declares logging macros
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CXFCLOGGER_H
       
    20 #define CXFCLOGGER_H
       
    21 
       
    22 #include "logdef.h"
       
    23 
       
    24 /**
       
    25  *  @file CXFCLogger.h
       
    26  *	@brief	Declares logging macros.
       
    27  *
       
    28  *  @note Link to flogger.lib in MMP file. Use DEBUGLIBRARY -keyword to avoid
       
    29  *        warnings in release builds.\n
       
    30  *		  @code DEBUGLIBRARY    flogger.lib @endcode
       
    31  *
       
    32  *  @b Usage: \n
       
    33  *		  @code LOG("[MODULE_NAME]\t Trace text here"); @endcode
       
    34  *
       
    35  *          Trace target can be changed below (file logging needs directory @c c:\\logs\\upnp )\n
       
    36  *          #define __FLOGGING__ -row uncommented (default)  = File logging \n
       
    37  *          #define __CLOGGING__ -row uncommented            = Console logging \n
       
    38  */
       
    39 
       
    40 
       
    41 #ifdef ENABLE_LOGGING
       
    42 // Define one of these flags:
       
    43 // FLOGGING = File logging
       
    44 // CLOGGING = Console logging
       
    45 #define __FLOGGING__
       
    46 //#define __CLOGGING__
       
    47 #endif
       
    48 
       
    49 // Then actual definitions depending on the
       
    50 // flag values.
       
    51 
       
    52 #ifdef ENABLE_LOGGING
       
    53 
       
    54     #include <e32std.h>
       
    55     #include <f32file.h>
       
    56 
       
    57 
       
    58     // Actual log file name
       
    59     _LIT(KLogFile,"CXFPLog.txt");
       
    60 
       
    61     // Subdirectory under c:\logs -directory -- MUST EXIST.
       
    62     _LIT(KLogDir, "upnp");
       
    63 
       
    64 	/// The format in which the time is formatted in log
       
    65 	_LIT( KLogTimeFormat, "%02d.%02d:%02d:%06d ");
       
    66 	_LIT8( KLogTimeFormat8, "%02d.%02d:%02d:%06d ");
       
    67 
       
    68 	// The length of the string produced by KLogTimeFormat
       
    69 	const TInt KLogTimeFormatLength = 16;
       
    70 
       
    71 	// How many characters a log line can contain
       
    72 	const TInt KLogLineLength = 256;
       
    73 
       
    74 
       
    75     #include <f32file.h>
       
    76     #include <flogger.h>
       
    77 
       
    78 
       
    79     // Define the top level macros
       
    80     #define LOG(a) {Print( _L(a) ) ;}
       
    81    	#define LOG1(s, v) {Print( _L(s), v );}
       
    82    	#define LOG2(s, v1, v2) {Print( _L(s), v1, v2 );}
       
    83 
       
    84     #define LOG8(a) {Print8( _L8(a) );}
       
    85    	#define LOG81(s, v) {Print8( _L8(s), v );}
       
    86    	#define LOG82(s, v1, v2) {Print8( _L8(s), v1, v2 );}
       
    87 
       
    88     #ifdef __FLOGGING__
       
    89 
       
    90         inline void Print( TRefByValue<const TDesC> aText, ... )
       
    91             {
       
    92 		    VA_LIST args;
       
    93 		    VA_START( args, aText );
       
    94 
       
    95 		    TBuf<256> buf;
       
    96 		    buf.FormatList( aText, args );
       
    97 
       
    98 			RFileLogger logger;
       
    99 			TInt ret = logger.Connect();
       
   100 			if (ret==KErrNone)
       
   101 				{
       
   102 				logger.SetDateAndTime( EFalse,EFalse );
       
   103 				logger.CreateLog( KLogDir, KLogFile, EFileLoggingModeAppend );
       
   104 				TBuf<KLogTimeFormatLength> timeStamp;
       
   105 				TTime now;
       
   106 				now.HomeTime();
       
   107 				TDateTime dateTime;
       
   108 				dateTime = now.DateTime();
       
   109 				timeStamp.Format( KLogTimeFormat,
       
   110 		            dateTime.Hour(), dateTime.Minute(),
       
   111 		            dateTime.Second(), dateTime.MicroSecond() );
       
   112 				buf.Insert( 0, timeStamp );
       
   113 
       
   114 				logger.Write(buf);
       
   115 				}
       
   116 
       
   117 			logger.Close();
       
   118 		    VA_END( args );
       
   119             }
       
   120 
       
   121         inline void Print8( TRefByValue<const TDesC8> aText, ... )
       
   122             {
       
   123 		    VA_LIST args;
       
   124 		    VA_START( args, aText );
       
   125 
       
   126 		    TBuf8<256> buf;
       
   127 		    buf.FormatList( aText, args );
       
   128 
       
   129 			RFileLogger logger;
       
   130 			TInt ret = logger.Connect();
       
   131 			if (ret==KErrNone)
       
   132 				{
       
   133 				logger.SetDateAndTime( EFalse,EFalse );
       
   134 				logger.CreateLog( KLogDir, KLogFile, EFileLoggingModeAppend );
       
   135 				TBuf8<KLogTimeFormatLength> timeStamp;
       
   136 				TTime now;
       
   137 				now.HomeTime();
       
   138 				TDateTime dateTime;
       
   139 				dateTime = now.DateTime();
       
   140 				timeStamp.Format( KLogTimeFormat8,
       
   141 		            dateTime.Hour(), dateTime.Minute(),
       
   142 		            dateTime.Second(), dateTime.MicroSecond() );
       
   143 				buf.Insert( 0, timeStamp );
       
   144 
       
   145 				logger.Write(buf);
       
   146 				}
       
   147 
       
   148 			logger.Close();
       
   149 		    VA_END( args );
       
   150             }
       
   151 
       
   152     #else
       
   153         // Console Logging on
       
   154         #define Print RDebug::Print
       
   155 
       
   156 	    #define LOGS(a1, a2) {\
       
   157 	    	TBuf<1000> log;\
       
   158 	    	log.Append(_L(a1));\
       
   159 			log.Append(a2);\
       
   160 			Print(log );}
       
   161 
       
   162 	    #define LOG8S(a1, a2) {\
       
   163 	    	TBuf8<1000> log;\
       
   164 	    	log.Append(_L8(a1));\
       
   165 			log.Append(a2);\
       
   166 			Print(log );}
       
   167     #endif  // __FLOGGING__
       
   168 
       
   169 #else
       
   170 
       
   171     // DEBUG build is not on --> no logging at all
       
   172     #define LOG(a)
       
   173    	#define LOG1(s, v)
       
   174    	#define LOG2(s, v1, v2)
       
   175 
       
   176     #define LOG8(a)
       
   177    	#define LOG81(s, v)
       
   178    	#define LOG82(s, v1, v2)
       
   179 
       
   180 #endif  // ENABLE_LOGGING
       
   181 
       
   182 #endif  // CXFCLOGGER_H
       
   183 
       
   184 // End of File