backupandrestore/backupengine/src/sblog.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of logging functions
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "sblog.h"
       
    23 
       
    24 namespace conn
       
    25 	{
       
    26 	
       
    27 	namespace securebackuplog 
       
    28 		{
       
    29         #if (defined(SBE_LOGGING_DEBUG_ONLY) && defined(_DEBUG)) || defined(SBE_LOGGING_DEBUG_AND_RELEASE)
       
    30 
       
    31         /** The flogger directory
       
    32     	@internalComponent */    
       
    33     	_LIT(KLogDirectory,"connect");
       
    34 
       
    35     	/** The flogger file
       
    36     	 @internalComponent */
       
    37         _LIT(KLogFile, "securebackup.txt");
       
    38 
       
    39         /** The maximum length of text that can be logged
       
    40     	 @internalComponent */
       
    41     	const TInt KMaxLogData = 0x200;
       
    42     
       
    43         void __LogRaw( TDes& aData )
       
    44         /** Performs the logging operation based upon SBEngine.mmh macro configuration
       
    45 		@param aData The data to be logged
       
    46         */
       
    47             {
       
    48 		    #if defined(SBE_LOGGING_METHOD_FLOGGER)
       
    49 	        	RFileLogger::Write(KLogDirectory, KLogFile, EFileLoggingModeAppend, aData);
       
    50 	    	#endif    
       
    51 
       
    52             #if defined(SBE_LOGGING_METHOD_RDEBUG) || defined(SBE_LOGGING_METHOD_UI)
       
    53             
       
    54             /** The logging component name
       
    55     		 @internalComponent */
       
    56         	_LIT(KLogComponentName, "[SBE] ");
       
    57         	
       
    58                 aData.Insert( 0, KLogComponentName );
       
    59 
       
    60                 #if defined( SBE_LOGGING_METHOD_UI )
       
    61                     User::InfoPrint( aData );
       
    62                 #endif
       
    63             	#if defined( SBE_LOGGING_METHOD_RDEBUG )
       
    64                 	RDebug::Print( _L("%S"), &aData );
       
    65             	#endif
       
    66             #endif
       
    67             }
       
    68 
       
    69 
       
    70 
       
    71 
       
    72 		void __Log( TRefByValue<const TDesC> aFmt, ... )	
       
    73 	 	/** Logs a message to FLOGGER and to the UI depending on
       
    74 	 	controlling macros.
       
    75 	 	
       
    76 	 	Note that FLOG macros are probably disabled in release builds, 
       
    77 	 	so we might need to use something else for logging to files
       
    78 
       
    79 		@internalComponent
       
    80 		@param aFmt The formatting codes
       
    81         */
       
    82 			{
       
    83 			VA_LIST list;
       
    84 		    VA_START(list,aFmt);
       
    85 		    
       
    86 		    TBuf< KMaxLogData > buf;
       
    87 		    buf.FormatList(aFmt,list); 
       
    88 		    
       
    89             __LogRaw( buf );
       
    90 			}
       
    91 
       
    92 
       
    93         void __DebugDump( const TDesC& aFormat, const TUint8* aAddress, TInt aLength )
       
    94         /** Logs binary data as ASCII (hex encoded). Useful for debugging data transfer
       
    95         @param aFormat The format specifier, must always include a string format identifer, i.e. <code>%S</code>
       
    96         @param aAddress The starting memory address containing data that is to be logged
       
    97         @param aLength The amount of data (in bytes) to log, starting at <code>aAddress</code>
       
    98         */
       
    99             {
       
   100         	_LIT( KEndOfAddressText, ": ");
       
   101             _LIT( KDoubleSpace, "  " );
       
   102             _LIT( KSingleSpace, " " );
       
   103 
       
   104             TInt len = aLength;
       
   105             const TInt maxLen = aLength;
       
   106             const TUint8* pDataAddr = aAddress;
       
   107 
       
   108             TBuf<KMaxLogData> formatBuffer;
       
   109         	TBuf<81> out;
       
   110         	TBuf<20> ascii;
       
   111         	TInt offset = 0;
       
   112         	const TUint8* a = pDataAddr;
       
   113             //
       
   114         	while(len>0)
       
   115         		{
       
   116         		out.Zero();
       
   117         		ascii.Zero();
       
   118         		out.AppendNumFixedWidth((TUint) a, EHex, 8);
       
   119         		out.Append( KEndOfAddressText );
       
   120 
       
   121                 TUint b;
       
   122         		for (b=0; b<16; b++)
       
   123         			{
       
   124                     TUint8 c = ' ';
       
   125                     if	((pDataAddr + offset + b) < pDataAddr + maxLen)
       
   126         	            {
       
   127         	            c = *(pDataAddr + offset + b);
       
   128         				out.AppendNumFixedWidth(c, EHex, 2);
       
   129         	            }
       
   130                     else
       
   131         	            {
       
   132         				out.Append( KDoubleSpace );
       
   133         	            }
       
   134 
       
   135                     out.Append( KSingleSpace );
       
   136 
       
   137                     if (c<0x20 || c>=0x7f || c=='%')
       
   138         				c=0x2e;
       
   139 
       
   140                     ascii.Append(TChar(c));
       
   141         			}
       
   142         		
       
   143                 out.Append(ascii);
       
   144                 out.ZeroTerminate();
       
   145 
       
   146                 formatBuffer.Format( aFormat, &out );
       
   147                 __LogRaw( formatBuffer );
       
   148 
       
   149                 a += 16;
       
   150         		offset += 16;
       
   151         		len -= 16;
       
   152                 }
       
   153             }
       
   154 			
       
   155         #endif
       
   156 		}//securebackuplog
       
   157 	}