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