emailservices/emaildebug/inc/emailtrace.h
changeset 0 8466d47a6819
child 8 e1b6206813b4
child 18 578830873419
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 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:  Header file describing trace utilities for commonemail
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef EMAILTRACE_H
       
    19 #define EMAILTRACE_H
       
    20 
       
    21 #include "emailtraceconfig.hrh"
       
    22 
       
    23 #ifdef TRACE_INTO_FILE
       
    24 #include "cmaillogger.h"
       
    25 #include <flogger.h> // RFileLogger
       
    26 #else
       
    27 #include <e32debug.h> // RDebug
       
    28 #endif
       
    29 
       
    30 /**
       
    31 * Constants
       
    32 */
       
    33 #if defined(TRACE_INTO_FILE)
       
    34 
       
    35     _LIT(  KEmailDir, "email" );
       
    36     _LIT(  KEmailTraceFile, "email.txt" );
       
    37 
       
    38 #endif
       
    39 
       
    40 #if defined(TRACE_FILE_LIMIT_SIZE)
       
    41     #define CMAIL_LOG_CLOSE CmailLogger::Close();
       
    42     #define CMAILLOGBUFFERSIZE 120
       
    43 #else
       
    44     #define CMAIL_LOG_CLOSE 
       
    45 #endif
       
    46 
       
    47 //-----------------------------------------------------------------------------
       
    48 // Error trace macros
       
    49 //-----------------------------------------------------------------------------
       
    50 //
       
    51 
       
    52 #ifdef ERROR_TRACE
       
    53 
       
    54     /**
       
    55     * Error trace definitions. Does not automatically log the error code!
       
    56     */    
       
    57     #if defined(TRACE_INTO_FILE) && !defined(TRACE_FILE_LIMIT_SIZE)
       
    58 
       
    59         #define ERROR( aErr, aMsg )\
       
    60             {\
       
    61             if( aErr != KErrNone )\
       
    62                 {\
       
    63                 _LIT( KMsg, aMsg );\
       
    64                 RFileLogger::Write(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg );\
       
    65                 }\
       
    66             }
       
    67         #define ERROR_1( aErr, aMsg, aP1 )\
       
    68             {\
       
    69             if( aErr != KErrNone )\
       
    70                 {\
       
    71                 _LIT( KMsg, aMsg );\
       
    72                 RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg, aP1 );\
       
    73                 }\
       
    74             }
       
    75         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
    76             {\
       
    77             if( aErr != KErrNone )\
       
    78                 {\
       
    79                 _LIT( KMsg, aMsg );\
       
    80                 RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg, aP1, aP2 );\
       
    81                 }\
       
    82             }
       
    83         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
    84             {\
       
    85             if( aErr != KErrNone )\
       
    86                 {\
       
    87                 _LIT( KMsg, aMsg );\
       
    88                 RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg, aP1, aP2, aP3 );\
       
    89                 }\
       
    90             }
       
    91         #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
       
    92         #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
       
    93     #endif
       
    94     #if defined(TRACE_INTO_FILE) && defined(TRACE_FILE_LIMIT_SIZE)
       
    95     
       
    96         #define ERROR( aErr, aMsg )\
       
    97         {\
       
    98             if( aErr != KErrNone )\
       
    99             {\
       
   100             _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KMsg(); if ( KMsg().Size() < buf.MaxSize() ) { CmailLogger::Write( buf ); }}\
       
   101         }    
       
   102     
       
   103     #define ERROR_1( aErr, aMsg, aP1 )\
       
   104         {\
       
   105             if( aErr != KErrNone )\
       
   106             {\
       
   107             _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KNullDesC8(); if ( KMsg().Size() < buf.MaxSize() ) { buf.Format( KMsg, aP1 ); CmailLogger::Write( buf ); } }\
       
   108         }    
       
   109         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
   110         {\
       
   111             if( aErr != KErrNone )\
       
   112             {\
       
   113             _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KNullDesC8(); if ( KMsg().Size() < buf.MaxSize() ) { buf.Format( KMsg, aP1, aP2 ); CmailLogger::Write( buf ); }} \
       
   114         }    
       
   115         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   116         {\
       
   117             if( aErr != KErrNone )\
       
   118             {\
       
   119             _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KNullDesC8(); if ( KMsg().Size() < buf.MaxSize() ) { buf.Format( KMsg, aP1, aP2, aP3 ); CmailLogger::Write( buf ); }}\
       
   120         }        
       
   121     #endif
       
   122     #if !defined(TRACE_INTO_FILE) && !defined(TRACE_FILE_LIMIT_SIZE)
       
   123 
       
   124         #define ERROR( aErr, aMsg )\
       
   125             {\
       
   126             if( aErr != KErrNone )\
       
   127                 {\
       
   128                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg );\
       
   129                 }\
       
   130             }
       
   131         #define ERROR_1( aErr, aMsg, aP1 )\
       
   132             {\
       
   133             if( aErr != KErrNone )\
       
   134                 {\
       
   135                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1 );\
       
   136                 }\
       
   137             }
       
   138         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
   139             {\
       
   140             if( aErr != KErrNone )\
       
   141                 {\
       
   142                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2 );\
       
   143                 }\
       
   144             }
       
   145         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   146             {\
       
   147             if( aErr != KErrNone )\
       
   148                 {\
       
   149                 _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2, aP3 );\
       
   150                 }\
       
   151             }
       
   152         #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
       
   153         #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
       
   154 
       
   155     #endif//TRACE_INTO_FILE
       
   156 
       
   157 #else//ERROR_TRACE not defined
       
   158 
       
   159     #define ERROR( aErr, aMsg )
       
   160     #define ERROR_1( aErr, aMsg, aP1 )
       
   161     #define ERROR_2( aErr, aMsg, aP1, aP2 )
       
   162     #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )
       
   163     #define ERROR_GEN( aMsg )
       
   164     #define ERROR_GEN_1( aMsg, aP1 )
       
   165 
       
   166 #endif//ERROR_TRACE
       
   167 
       
   168 
       
   169 //-----------------------------------------------------------------------------
       
   170 // Info trace macros
       
   171 //-----------------------------------------------------------------------------
       
   172 //
       
   173 #if defined(INFO_TRACE)
       
   174 
       
   175     /**
       
   176     * Info log message definitions.
       
   177     */
       
   178     #if defined(TRACE_INTO_FILE) && !defined(TRACE_FILE_LIMIT_SIZE)
       
   179 
       
   180         #define INFO( aMsg )\
       
   181             {\
       
   182             _LIT( KMsg, aMsg );\
       
   183             RFileLogger::Write(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg );\
       
   184             }
       
   185         #define INFO_1( aMsg, aP1 )\
       
   186             {\
       
   187             _LIT( KMsg, aMsg );\
       
   188             RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg, aP1 );\
       
   189             }
       
   190         #define INFO_2( aMsg, aP1, aP2 )\
       
   191             {\
       
   192             _LIT( KMsg, aMsg );\
       
   193             RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg, aP1, aP2 );\
       
   194             }
       
   195         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   196             {\
       
   197             _LIT( KMsg, aMsg );\
       
   198             RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg, aP1, aP2, aP3 );\
       
   199             }
       
   200     #endif // // TRACE_INTO_FILE && TRACE_FILE_LIMIT_SIZE
       
   201     
       
   202     #if defined(TRACE_INTO_FILE) && defined(TRACE_FILE_LIMIT_SIZE)
       
   203         #define CMAIL_LOG_INIT
       
   204         
       
   205         #define INFO( aMsg )\
       
   206             {\
       
   207             _LIT8( KMsg, aMsg );\
       
   208             CmailLogger::Write( KMsg );\
       
   209             }
       
   210         #define INFO_1( aMsg, aP1 )\
       
   211             { _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KNullDesC8();\
       
   212              if ( KMsg().Size() < buf.MaxSize() ) { buf.Format( KMsg, aP1 ); }\
       
   213                 CmailLogger::Write( buf ); }
       
   214         #define INFO_2( aMsg, aP1, aP2 )\
       
   215             { _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KNullDesC8();\
       
   216              if ( KMsg().Size() < buf.MaxSize() ) { buf.Format( KMsg, aP1,aP2 ); }\
       
   217                 CmailLogger::Write( buf ); }
       
   218         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   219             { _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KNullDesC8();\
       
   220              if ( KMsg().Size() < buf.MaxSize() ) { buf.Format( KMsg, aP1,aP2,aP3 ); }\
       
   221                 CmailLogger::Write( buf ); }
       
   222     #endif // TRACE_INTO_FILE && TRACE_FILE_LIMIT_SIZE
       
   223     #if !defined(TRACE_INTO_FILE)
       
   224 
       
   225         #define INFO( aMsg )\
       
   226             {\
       
   227             _LIT( KMsg, aMsg ); RDebug::Print( KMsg );\
       
   228             }
       
   229         #define INFO_1( aMsg, aP1 )\
       
   230             {\
       
   231             _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1 );\
       
   232             }
       
   233         #define INFO_2( aMsg, aP1, aP2 )\
       
   234             {\
       
   235             _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2 );\
       
   236             }
       
   237         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   238             {\
       
   239             _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aP1, aP2, aP3 );\
       
   240             }
       
   241 
       
   242     #endif//TRACE_INTO_FILE
       
   243                            
       
   244 #else//INFO_TRACE not defined
       
   245     
       
   246     #define CMAIL_LOG_INIT
       
   247     #define CMAIL_LOG_CLOSE
       
   248     #define INFO( aMsg )
       
   249     #define INFO_1( aMsg, aP1 )
       
   250     #define INFO_2( aMsg, aP1, aP2 )
       
   251     #define INFO_3( aMsg, aP1, aP2, aP3 )
       
   252 
       
   253 #endif//INFO_TRACE
       
   254 
       
   255 //-----------------------------------------------------------------------------
       
   256 // Function trace macros
       
   257 //-----------------------------------------------------------------------------
       
   258 //
       
   259  
       
   260 #if defined (FUNC_TRACE)
       
   261 
       
   262     // Constants
       
   263     _LIT8( KEllipse, "(" );
       
   264 
       
   265     //
       
   266     // Function logging definitions.
       
   267     //
       
   268     
       
   269     
       
   270     #if defined(TRACE_FILE_LIMIT_SIZE)
       
   271         #define FUNC( aMsg, aP1 )\
       
   272         {\
       
   273             _LIT8( KMsg, aMsg );TBuf8<CMAILLOGBUFFERSIZE> buf=KNullDesC8(); if ( KMsg().Size() < buf.MaxSize() ) { buf.Format( KMsg, aP1 ); }CmailLogger::Write( buf ); }
       
   274     #endif
       
   275     #if defined(TRACE_INTO_FILE) && !defined(TRACE_FILE_LIMIT_SIZE)
       
   276         #define FUNC( aMsg, aP1 )\
       
   277             {\
       
   278             _LIT8( KMsg, aMsg ); RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KMsg, aP1 );\
       
   279             }
       
   280     #endif
       
   281     #if !defined(TRACE_INTO_FILE) 
       
   282         #define FUNC( aMsg, aP1 )\
       
   283             {\
       
   284             RDebug::Printf( aMsg, aP1 );\
       
   285             }\
       
   286 
       
   287     #endif//TRACE_INTO_FILE
       
   288     
       
   289     /**
       
   290     * Function trace helper class.
       
   291     */
       
   292     class TFuncLog
       
   293         {
       
   294         public:
       
   295             inline TFuncLog( const char* aFunc ): iFunc( (TUint8*)aFunc )
       
   296                 {
       
   297                 TInt pos = iFunc.Find( KEllipse );
       
   298                 if( pos != KErrNotFound )
       
   299                     {
       
   300                     iFunc.Set( iFunc.Left( iFunc.Find( KEllipse ) ) );
       
   301                     }
       
   302                 #if defined(TRACE_INTO_FILE) && !defined(TRACE_FILE_LIMIT_SIZE)
       
   303 
       
   304                     //"CMAIL" string is added in the beginning of every trace
       
   305                     //line for filtering purposes
       
   306                     FUNC( "CMAIL %S <", &iFunc );
       
   307                 #endif
       
   308                 #if defined(TRACE_INTO_FILE) && defined(TRACE_FILE_LIMIT_SIZE)
       
   309                     TBuf8<CMAILLOGBUFFERSIZE> buf(iFunc);
       
   310                     buf.Append(_L("<"));
       
   311                     CmailLogger::Write( buf );
       
   312                 #endif
       
   313                 #if !defined(TRACE_INTO_FILE)
       
   314 
       
   315                     FUNC( "CMAIL %s <", iFunc.Ptr() );
       
   316 
       
   317                 #endif//TRACE_INTO_FILE
       
   318                 }
       
   319             inline ~TFuncLog()
       
   320                 {
       
   321                 #if defined(TRACE_INTO_FILE) && !defined(TRACE_FILE_LIMIT_SIZE)
       
   322                     FUNC( "CMAIL %S >", &iFunc );
       
   323                 #endif
       
   324                 #if defined(TRACE_INTO_FILE) && defined(TRACE_FILE_LIMIT_SIZE)
       
   325                     TBuf8<CMAILLOGBUFFERSIZE> buf(iFunc);
       
   326                     buf.Append(_L(">"));
       
   327                     CmailLogger::Write( buf );
       
   328                 #endif
       
   329                 #if !defined(TRACE_INTO_FILE)
       
   330 
       
   331                     FUNC( "CMAIL %s >", iFunc.Ptr() );
       
   332                 #endif//TRACE_INTO_FILE
       
   333                 }
       
   334             TPtrC8 iFunc;
       
   335         };
       
   336 
       
   337     #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
       
   338 #else//FUNC_TRACE not defined
       
   339 
       
   340     #define FUNC_LOG
       
   341 
       
   342 #endif//FUNC_TRACE
       
   343 
       
   344 //-----------------------------------------------------------------------------
       
   345 // Timestamp trace macros
       
   346 //-----------------------------------------------------------------------------
       
   347 //
       
   348 #if defined(TIMESTAMP_TRAC)
       
   349 
       
   350     #if defined(TRACE_INTO_FIL)
       
   351 
       
   352         #define TIMESTAMP( aCaption )\
       
   353             {\
       
   354             TTime t;\
       
   355             t.HomeTime();\
       
   356             TDateTime dt = t.DateTime();\
       
   357             _LIT( KMsg, aCaption );\
       
   358             _LIT( KFormat, "[TIMESTAMP] %S %d:%02d:%02d.%d us");\
       
   359             RFileLogger::WriteFormat(  KEmailDir,  KEmailTraceFile, EFileLoggingModeAppend, KFormat,\
       
   360                 &KMsg, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
       
   361             }
       
   362 
       
   363     #else//TRACE_INTO_FILE not defined
       
   364 
       
   365         #define TIMESTAMP( aCaption )\
       
   366             {\
       
   367             TTime t;\
       
   368             t.HomeTime();\
       
   369             TDateTime dt = t.DateTime();\
       
   370             _LIT( KMsg, aCaption );\
       
   371             _LIT( KFormat, "[TIMESTAMP] %S %d:%02d:%02d.%d us");\
       
   372             RDebug::Print( KFormat,\
       
   373                 &KMsg, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
       
   374             }
       
   375 
       
   376     #endif//TRACE_INTO_FILE
       
   377 
       
   378 #else//TIMESTAMP_TRACE not defined
       
   379 
       
   380     #define TIMESTAMP( aCaption )
       
   381 
       
   382 #endif//TIMESTAMP_TRACE
       
   383 
       
   384 #endif // EMAILTRACE_H