omads/omadsextensions/adapters/mms/inc/logger.h
branchRCL_3
changeset 51 8e7494275d3a
parent 0 dab8a81a92de
child 52 4f0867e42d62
equal deleted inserted replaced
48:2bb96f4ecad8 51:8e7494275d3a
     1 /*
     1 /*
     2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 #ifndef __LOGGER_H__
    19 #ifndef __LOGGER_H__
    20 #define __LOGGER_H__
    20 #define __LOGGER_H__
    21 
    21 
    22 #ifdef _DEBUG
    22 #ifdef _DEBUG
    23     #ifdef __WINS__
    23     
    24         // File logging for WINS
    24     // Define this to enable file logging
    25         #define __FLOGGING__
    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     
    26     
    32     #include <f32file.h>
    27     #include <f32file.h>
    33     #include <flogger.h>
    28     #include <flogger.h>
    34     #include <e32std.h>
    29     #include <e32std.h>
    35     #include <e32def.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         };
    36     
    43     
    37     _LIT(KLogDir,"MMS");
    44     _LIT(KLogDir,"MMS");
    38     _LIT(KLogFile,"MMSDataproviderLog.txt");
    45     _LIT(KLogFile,"MMSDataproviderLog.txt");
    39     _LIT( KLogFormat, "[MMSDS] %S");
    46     _LIT( KLogFormat, "[MMSDS] %S");
    40     
    47     
    41     _LIT(KLogEnterFn, "%S : Begin");
    48     _LIT(KTracePrefix16, "[MMSDS] ");
    42     _LIT(KLogLeaveFn, "%S : End");
    49     _LIT8(KTracePrefix8, "[MMSDS] ");
       
    50     _LIT8(KFuncEntryFormat8, "%S : Begin");
       
    51     _LIT8(KFuncExitFormat8, "%S : End");
       
    52     _LIT8(KFuncFormat8, "><%S");
       
    53     
       
    54     const TInt KMaxLogLineLength = 512;
    43     
    55     
    44     /**
    56     /**
    45     * Old logging macros, for public use
    57     * Old logging macros
    46     */
    58     */
    47     #ifdef __FLOGGING__
    59     #ifdef __FLOGGING__
    48         #define LOG( AAA )      RFileLogger::Write( KLogDir,KLogFile,EFileLoggingModeAppend,AAA )
    60         #define LOG( AAA )      RFileLogger::Write( KLogDir,KLogFile,EFileLoggingModeAppend,AAA )
    49     #else
    61     #else
    50         #define LOG( AAA )
    62         #define LOG( AAA )
    51     #endif
    63     #endif
    52     #define LOG2( text, par1 )       { FPrint( text, par1 ); }
       
    53     
    64     
    54     
    65     
    55     /**
    66     // old function loggin macros
    56     * new logging macros, for public use
    67     #define LOGGER_ENTERFN( name )      {TRACE_FUNC_ENTRY;}
    57     */
    68     #define LOGGER_LEAVEFN( name )      {TRACE_FUNC_EXIT;}
    58     #define LOGGER_ENTERFN( name )      {_LIT( temp, name ); FPrint( KLogEnterFn, &temp );}
       
    59     #define LOGGER_LEAVEFN( name )      {_LIT( temp, name ); FPrint( KLogLeaveFn, &temp );}
       
    60     
    69     
    61     #define LOGGER_WRITE( text )                    {_LIT( KTemp, text ); FPrint( KTemp );}
    70     #define LOGGER_WRITE( text )             {_LIT( KTemp, text ); FPrint( KTemp );}
    62     #define LOGGER_WRITE_1( text,par1 )             {_LIT( KTemp, text ); FPrint( KTemp, par1 );}
    71     #define LOGGER_WRITE_1( text,par1 )      {_LIT( KTemp, text ); FPrint( KTemp, par1 );}
    63     #define LOGGER_MSG_EC( 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);}
    64     
    78     
    65     
    79     
    66     // Declare the FPrint function
    80     // Declare the FPrint function
    67     inline void FPrint( TRefByValue<const TDesC> aFmt, ...)
    81     inline void FPrint( TRefByValue<const TDesC16> aFmt, ...)
    68         {
    82         {
    69         VA_LIST list;
    83         VA_LIST list;
    70         VA_START(list,aFmt);
    84         VA_START(list,aFmt);
    71         #if defined ( __FLOGGING__ )
    85     #if defined ( __FLOGGING__ )
    72             RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
    86             RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
    73         #endif
    87     #endif
    74         #if defined ( __CLOGGING__ )
    88         
    75             const TInt KMaxLogData = 0x200;
    89         TBuf16<KMaxLogLineLength> theFinalString;
    76     	    TBuf< KMaxLogData > buf;
    90         theFinalString.Append(KTracePrefix16);
    77     	    buf.FormatList( aFmt, list );
    91         TOverflowTruncate16 overflow;
    78     	    
    92         theFinalString.AppendFormatList(aFmt,list,&overflow);
    79     	    RDebug::Print( KLogFormat, &buf );
    93         RDebug::Print(theFinalString);
    80         #endif
    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);
    81         }
   111         }
    82 #else // no _DEBUG defined
   112 #else // no _DEBUG defined
    83     
   113     
    84     #define LOG( AAA )
   114     #define LOG( A )
    85     
   115     
    86     #define LOGGER_ENTERFN( name )
   116     #define LOGGER_ENTERFN( name )
    87     #define LOGGER_LEAVEFN( name )
   117     #define LOGGER_LEAVEFN( name )
    88     #define LOGGER_WRITE( text )
   118     #define LOGGER_WRITE( text )
    89     #define LOGGER_WRITE_1( text,par1 )
   119     #define LOGGER_WRITE_1( text,par1 )
    90     #define LOGGER_MSG_EC( 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     
    91 
   126 
    92 #endif // _DEBUG
   127 #endif // _DEBUG
    93 
   128 
    94 #endif // __LOGGER_H__
   129 #endif // __LOGGER_H__
    95 
   130