omads/omadsextensions/adapters/contactsgroup/inc/logger.h
branchRCL_3
changeset 52 4f0867e42d62
parent 51 8e7494275d3a
child 56 3e6957da2ff8
equal deleted inserted replaced
51:8e7494275d3a 52:4f0867e42d62
     1 /*
       
     2 * Copyright (c) 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:  Debug utility for Contact Groups
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef _LOGGER_H
       
    20 #define _LOGGER_H
       
    21 
       
    22 #ifdef _DEBUG
       
    23     
       
    24     // Define this to enable file logging
       
    25     #define __FLOGGING__
       
    26     
       
    27     #include <e32svr.h>
       
    28     #ifdef __FLOGGING__
       
    29         #include <f32file.h>
       
    30         #include <flogger.h>
       
    31     #endif
       
    32     
       
    33     NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    34         {
       
    35     public:
       
    36         void Overflow(TDes16& /*aDes*/) {}
       
    37         };
       
    38     
       
    39     NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    40         {
       
    41     public:
       
    42         void Overflow(TDes8& /*aDes*/) {}
       
    43         };
       
    44     
       
    45     _LIT( KLogDir, "CNTGRP" );
       
    46     _LIT( KLogFile, "ContactsGroupLog.txt" );
       
    47     
       
    48     _LIT(KTracePrefix16, "[CNTGRP] ");
       
    49     _LIT8(KTracePrefix8, "[CNTGRP] ");
       
    50     _LIT8(KFuncEntryFormat8, "%S : Begin");
       
    51     _LIT8(KFuncExitFormat8, "%S : End");
       
    52     _LIT8(KFuncFormat8, "><%S");
       
    53     
       
    54     const TInt KMaxLogLineLength = 512;
       
    55     
       
    56     #define LOGGER_WRITE( text )                    {_LIT( KTemp, text ); FPrint( KTemp );}
       
    57     #define LOGGER_WRITE_1( text,par1 )             {_LIT( KTemp, text ); FPrint( KTemp, par1 );}
       
    58     #define LOGGER_WRITE8_1( text,par1 )             {_LIT8( KTemp, text ); FPrint( KTemp, par1 );}
       
    59     #define LOGGER_WRITE_2( text,par1,par2 )        {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );}
       
    60     #define LOGGER_WRITE_3( text,par1,par2,par3 )   {_LIT( KTemp, text ); FPrint( KTemp, par1, par2, par3 );}
       
    61     #define LOGGER_WRITE_IFERR_2( text, err )       {if (err) {_LIT( KTemp, text ); FPrint( KTemp, err );}}
       
    62     
       
    63     // New function logging macros
       
    64     #define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);}
       
    65     #define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);}
       
    66     #define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);}
       
    67     
       
    68     // Declare the FPrint function
       
    69     inline void FPrint( TRefByValue<const TDesC16> aFmt, ...)
       
    70         {
       
    71         VA_LIST list;
       
    72         VA_START(list,aFmt);
       
    73     #ifdef __FLOGGING__
       
    74         RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
       
    75     #endif
       
    76         TBuf16<KMaxLogLineLength> theFinalString;
       
    77         theFinalString.Append(KTracePrefix16);
       
    78         TOverflowTruncate16 overflow;
       
    79         theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    80         RDebug::Print(theFinalString);
       
    81         }
       
    82     
       
    83     // Declare the FPrint function
       
    84     inline void FPrint(TRefByValue<const TDesC8> aFmt, ...)
       
    85         {
       
    86         VA_LIST list;
       
    87         VA_START(list, aFmt);
       
    88     #ifdef __FLOGGING__
       
    89         RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    90     #endif
       
    91         TOverflowTruncate8 overflow;
       
    92         TBuf8<KMaxLogLineLength> buf8;
       
    93         buf8.Append(KTracePrefix8);
       
    94         buf8.AppendFormatList(aFmt, list, &overflow);
       
    95         TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
    96         buf16.Copy(buf8);
       
    97         TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
    98         RDebug::Print(tmpFmt, &buf16);
       
    99         }
       
   100 #else
       
   101     
       
   102     // No loggings --> reduced code size
       
   103     #define LOGGER_WRITE( text )
       
   104     #define LOGGER_WRITE_1( text, par1 )
       
   105     #define LOGGER_WRITE8_1( text,par1 )
       
   106     #define LOGGER_WRITE_2( text, par1, par2 )
       
   107     #define LOGGER_WRITE_3( text, par1, par2, par3 )
       
   108     #define TRACE_FUNC_ENTRY
       
   109     #define TRACE_FUNC_EXIT
       
   110     #define TRACE_FUNC
       
   111 
       
   112 #endif //_DEBUG
       
   113 
       
   114 #endif // SECON_DEBUG_H
       
   115 
       
   116 // End of file
       
   117