omads/omadsextensions/adapters/mms/inc/logger.h
changeset 40 b63e67867dcd
equal deleted inserted replaced
39:9905f7d46607 40:b63e67867dcd
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  Logging macros used by DS plug-in adapters
       
    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 <f32file.h>
       
    28     #include <flogger.h>
       
    29     #include <e32std.h>
       
    30     #include <e32def.h>
       
    31 
       
    32     NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    33         {
       
    34     public:
       
    35         void Overflow(TDes16& /*aDes*/) {}
       
    36         };
       
    37     
       
    38     NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    39         {
       
    40     public:
       
    41         void Overflow(TDes8& /*aDes*/) {}
       
    42         };
       
    43     
       
    44     _LIT(KLogDir,"MMS");
       
    45     _LIT(KLogFile,"MMSDataproviderLog.txt");
       
    46     _LIT( KLogFormat, "[MMSDS] %S");
       
    47     
       
    48     _LIT(KTracePrefix16, "[MMSDS] ");
       
    49     _LIT8(KTracePrefix8, "[MMSDS] ");
       
    50     _LIT8(KFuncEntryFormat8, "%S : Begin");
       
    51     _LIT8(KFuncExitFormat8, "%S : End");
       
    52     _LIT8(KFuncFormat8, "><%S");
       
    53     
       
    54     const TInt KMaxLogLineLength = 512;
       
    55     
       
    56     /**
       
    57     * Old logging macros
       
    58     */
       
    59     #ifdef __FLOGGING__
       
    60         #define LOG( AAA )      RFileLogger::Write( KLogDir,KLogFile,EFileLoggingModeAppend,AAA )
       
    61     #else
       
    62         #define LOG( AAA )
       
    63     #endif
       
    64     
       
    65     
       
    66     // old function loggin macros
       
    67     #define LOGGER_ENTERFN( name )      {TRACE_FUNC_ENTRY;}
       
    68     #define LOGGER_LEAVEFN( name )      {TRACE_FUNC_EXIT;}
       
    69     
       
    70     #define LOGGER_WRITE( text )             {_LIT( KTemp, text ); FPrint( KTemp );}
       
    71     #define LOGGER_WRITE_1( text,par1 )      {_LIT( KTemp, text ); FPrint( KTemp, par1 );}
       
    72     #define LOGGER_WRITE_2( text,par1,par2 ) {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );}
       
    73     
       
    74     // New function logging macros
       
    75     #define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);}
       
    76     #define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);}
       
    77     #define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);}
       
    78     
       
    79     
       
    80     // Declare the FPrint function
       
    81     inline void FPrint( TRefByValue<const TDesC16> aFmt, ...)
       
    82         {
       
    83         VA_LIST list;
       
    84         VA_START(list,aFmt);
       
    85     #if defined ( __FLOGGING__ )
       
    86             RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
       
    87     #endif
       
    88         
       
    89         TBuf16<KMaxLogLineLength> theFinalString;
       
    90         theFinalString.Append(KTracePrefix16);
       
    91         TOverflowTruncate16 overflow;
       
    92         theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    93         RDebug::Print(theFinalString);
       
    94         }
       
    95     
       
    96     inline void FPrint(TRefByValue<const TDesC8> aFmt, ...)
       
    97         {
       
    98         VA_LIST list;
       
    99         VA_START(list, aFmt);
       
   100     #ifdef __FLOGGING__
       
   101         RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
   102     #endif
       
   103         TOverflowTruncate8 overflow;
       
   104         TBuf8<KMaxLogLineLength> buf8;
       
   105         buf8.Append(KTracePrefix8);
       
   106         buf8.AppendFormatList(aFmt, list, &overflow);
       
   107         TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
   108         buf16.Copy(buf8);
       
   109         TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
   110         RDebug::Print(tmpFmt, &buf16);
       
   111         }
       
   112 #else // no _DEBUG defined
       
   113     
       
   114     #define LOG( A )
       
   115     
       
   116     #define LOGGER_ENTERFN( name )
       
   117     #define LOGGER_LEAVEFN( name )
       
   118     #define LOGGER_WRITE( text )
       
   119     #define LOGGER_WRITE_1( text,par1 )
       
   120     #define LOGGER_WRITE_2( text,par1,par2 )
       
   121     
       
   122     #define TRACE_FUNC_ENTRY
       
   123     #define TRACE_FUNC_EXIT 
       
   124     #define TRACE_FUNC
       
   125     
       
   126 
       
   127 #endif // _DEBUG
       
   128 
       
   129 #endif // __LOGGER_H__
       
   130