pkiutilities/ocsp/inc/log.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 // Copyright (c) 2006-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 // This header contains definitions for logging commands.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef __OCSP_LOG_H__
       
    24 #define __OCSP_LOG_H__
       
    25 
       
    26 #include <e32debug.h>
       
    27 
       
    28 namespace OCSP
       
    29 {
       
    30 
       
    31 #ifdef _DEBUG
       
    32 
       
    33 #define DEBUG_PRINTF(a) {OCSP::DebugPrintf(__LINE__, __FILE__, a);}
       
    34 #define DEBUG_PRINTF2(a, b) {OCSP::DebugPrintf(__LINE__, __FILE__, a, b);}
       
    35 #define DEBUG_PRINTF3(a, b, c) {OCSP::DebugPrintf(__LINE__, __FILE__, a, b, c);}
       
    36 #define DEBUG_PRINTF4(a, b, c, d) {OCSP::DebugPrintf(__LINE__, __FILE__, a, b, c, d);}
       
    37 #define DEBUG_PRINTF5(a, b, c, d, e) {OCSP::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);}
       
    38 
       
    39 #define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) 
       
    40 
       
    41 // UTF-8 overload of the DebufPrintf method. Should be used by default,
       
    42 // since it's cheaper both in CPU cycles and stack space.
       
    43 
       
    44 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC8> aFormat, ...)
       
    45 	{
       
    46 	VA_LIST list;
       
    47 	VA_START(list, aFormat);
       
    48 	
       
    49 	TTime now;
       
    50 	now.HomeTime();
       
    51 	
       
    52 	TBuf8<1024> buffer;
       
    53 	_LIT8(KSwiLogPrefix, "[OCSP] ");
       
    54 	_LIT8(KSwiLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
       
    55 	buffer.Append(KSwiLogPrefix);
       
    56 	buffer.AppendFormat(KSwiLineFileFormat, now.Int64(), aLine, aFile);
       
    57 	buffer.AppendFormatList(aFormat, list);
       
    58 	buffer.Append(_L8("\r\n"));
       
    59 	
       
    60 	RDebug::RawPrint(buffer);
       
    61 	
       
    62 	VA_END(list);
       
    63 	}
       
    64 	
       
    65 // Unicode DebufPrintf overload
       
    66 
       
    67 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC16> aFormat, ...)
       
    68 	{
       
    69 	VA_LIST list;
       
    70 	VA_START(list, aFormat);
       
    71 	
       
    72 	TTime now;
       
    73 	now.HomeTime();
       
    74 	
       
    75 	TBuf8<256> header;
       
    76 	_LIT8(KSwiLogPrefix, "[SWI] ");
       
    77 	_LIT8(KSwiLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
       
    78 	header.Append(KSwiLogPrefix);
       
    79 	header.AppendFormat(KSwiLineFileFormat, now.Int64(), aLine, aFile);
       
    80 	
       
    81 	TBuf<1024> buffer;
       
    82 	buffer.Copy(header);
       
    83 	buffer.AppendFormatList(aFormat, list);
       
    84 	buffer.Append(_L("\r\n"));
       
    85 	
       
    86 	RDebug::RawPrint(buffer);
       
    87 	
       
    88 	VA_END(list);
       
    89 	}
       
    90 
       
    91 #else
       
    92 
       
    93 #define DEBUG_PRINTF(a)
       
    94 #define DEBUG_PRINTF2(a, b)
       
    95 #define DEBUG_PRINTF3(a, b, c)
       
    96 #define DEBUG_PRINTF4(a, b, c, d)
       
    97 #define DEBUG_PRINTF5(a, b, c, d, e)
       
    98 
       
    99 #define DEBUG_CODE_SECTION(a)
       
   100 
       
   101 #endif
       
   102 
       
   103 
       
   104 } // namespace Swi
       
   105 
       
   106 #endif // __OCSP_LOG_H__