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