brandingserver/group/debugtrace.h
changeset 0 e6b17d312c8b
child 21 cfd5c2994f10
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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: Debug Traces.
       
    15 *
       
    16 */
       
    17 #ifndef __DEBUGTRACE_H__
       
    18 #define __DEBUGTRACE_H__
       
    19 
       
    20 //  INCLUDES
       
    21 #include  "e32std.h"
       
    22 
       
    23 //  DEFINES
       
    24 //Undefine: tracing disabled
       
    25 //Define 1: Traces goes to file log
       
    26 //Define 2: Traces goes to RDebug output
       
    27 //Define 3: Trace goes both file and RDebug output
       
    28 #undef TRACE_MODE
       
    29 //#define TRACE_MODE 3
       
    30 
       
    31 
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // Trace definitions
       
    35 // -----------------------------------------------------------------------------
       
    36 #ifdef TRACE_MODE
       
    37 
       
    38     //  INCLUDES
       
    39     #include <flogger.h>
       
    40     #include <e32svr.h>
       
    41 
       
    42     // CONSTANTS
       
    43     _LIT( KTraceLogDir, "BS" );
       
    44     _LIT( KTraceLogFile, "BS.log" );
       
    45 
       
    46      //TRACE INDIRECTION
       
    47     #define T_LIT(s) _L(s) // CSI: 78 # See above
       
    48     #define TRACE Trace::Emit
       
    49     #define IF_TRACE_ON( aStatement ) aStatement
       
    50 #endif  // TRACE_MODE
       
    51 
       
    52 
       
    53 //-----------------------------------------------------------------------------
       
    54 // Empty trace definitions
       
    55 //-----------------------------------------------------------------------------
       
    56 #ifndef TRACE_MODE
       
    57     struct TEmptyTraceString { };
       
    58     #define T_LIT(s) TEmptyTraceString()
       
    59     #define IF_TRACE_ON( aStatement )
       
    60 
       
    61     inline void TRACE(TEmptyTraceString){}
       
    62 
       
    63     template<class T1>
       
    64     inline void TRACE(TEmptyTraceString,T1){}
       
    65 
       
    66     template<class T1,class T2>
       
    67     inline void TRACE(TEmptyTraceString,T1,T2){}
       
    68 
       
    69     template<class T1,class T2,class T3>
       
    70     inline void TRACE(TEmptyTraceString,T1,T2,T3){}
       
    71 
       
    72     template<class T1,class T2,class T3,class T4>
       
    73     inline void TRACE(TEmptyTraceString,T1,T2,T3,T4){}
       
    74 
       
    75     template<class T1,class T2,class T3,class T4,class T5>
       
    76     inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5){}
       
    77 
       
    78     template<class T1,class T2,class T3,class T4,class T5,class T6>
       
    79     inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5,T6){}
       
    80 
       
    81     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7>
       
    82     inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5,T6,T7){}
       
    83 
       
    84     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
       
    85     inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5,T6,T7,T8){}
       
    86 
       
    87 #endif  // TRACE_MODE
       
    88 
       
    89 
       
    90 
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // Trace implementation
       
    94 // -----------------------------------------------------------------------------
       
    95 #ifdef TRACE_MODE
       
    96     #include <flogger.h>
       
    97     #include <e32svr.h>
       
    98 
       
    99     // TARGET WARNING
       
   100     #if !defined(_DEBUG)
       
   101 
       
   102     #if defined(__CW32__)
       
   103     #pragma message("Trace logging on.") // CSI: 68 # See above
       
   104     #else
       
   105     //ARMCC warning
       
   106     #endif
       
   107     #endif
       
   108 
       
   109     namespace Trace
       
   110         {
       
   111         class TOverflowHandler : public TDes16Overflow
       
   112             {
       
   113             inline void Overflow( TDes16& /*aDes*/ ) {}
       
   114             };
       
   115 
       
   116         inline void Emit( TRefByValue<const TDesC> aFmt, ... )
       
   117             {
       
   118             //Format the log line
       
   119             TBuf< 250 > buffer;
       
   120             buffer.Append( _L("[") ); // CSI: 78 # See above
       
   121             buffer.Append( RThread().Name() );
       
   122             buffer.Append( _L("] ") ); // CSI: 78 # See above
       
   123 
       
   124             TOverflowHandler overflowHandler;
       
   125 
       
   126             VA_LIST list;
       
   127             VA_START( list, aFmt );
       
   128             buffer.AppendFormatList( aFmt, list, &overflowHandler );
       
   129 
       
   130             TInt theTraceMode = TRACE_MODE;
       
   131 
       
   132             //Send trace to file
       
   133             if( ( theTraceMode == 1 ) ||
       
   134                 ( theTraceMode == 3 ) )
       
   135                 {
       
   136                 RFileLogger logger;
       
   137                 if( logger.Connect() == KErrNone )
       
   138                     {
       
   139                     logger.SetDateAndTime( EFalse, ETrue );
       
   140                     logger.CreateLog( KTraceLogDir,
       
   141                                       KTraceLogFile,
       
   142                                       EFileLoggingModeAppend );
       
   143 
       
   144                     logger.Write( buffer );
       
   145                     logger.CloseLog();
       
   146                     logger.Close();
       
   147                     }
       
   148                 }
       
   149 
       
   150             //Send trace to default debug output
       
   151             if( ( theTraceMode == 2 ) ||
       
   152                 ( theTraceMode == 3 ) )
       
   153                 {
       
   154                 RDebug::Print( _L("%S"), &buffer );
       
   155                 }
       
   156             }
       
   157         }
       
   158 #endif //TRACE_MODE
       
   159 
       
   160 #endif //__DEBUGTRACE_H__
       
   161 
       
   162 //  END OF FILE