taskswitcher/taskswitcherui/trace/tslogging.h
changeset 4 4d54b72983ae
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Defines all available logging macros.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TSLOGLOGUTILS_H
       
    20 #define TSLOGLOGUTILS_H
       
    21 
       
    22 /**
       
    23  * @file
       
    24  * 
       
    25  * TAKING LOGGING INTO USE:
       
    26  * 
       
    27  * This step is needed to do once per component.
       
    28  * 
       
    29  * For each component that uses these common logging macros should specify
       
    30  * their own logging configuration file, which includes this file. In that
       
    31  * configuration file, following constants and macros must be defined.
       
    32  *  For example:
       
    33  * @code
       
    34  * 
       
    35  * _LIT( KTsLogFile, "text_file_for_logging.txt" );
       
    36  * _LIT( KTsLogPath, "folder_for_text_file" );
       
    37  * #define _TSLOG_LOG_COMPONENT_ID <some unique number here>
       
    38  * 
       
    39  * #include "tslogging.h"
       
    40  * 
       
    41  * @/code
       
    42  * 
       
    43  * KTsLogFile   : This is the name of the file, where all the logs for
       
    44  *                this components are being written.
       
    45  * 
       
    46  * KTsLogPath   : This is the folder name under c:\logs, where the file
       
    47  *                is to be stored. For example, if KTsLogPath is "test",
       
    48  *                log file is created into folder c:\logs\test.
       
    49  * 
       
    50  * _TSLOG_LOG_COMPONENT_ID  : Unique number id of the component. This is 
       
    51  *                            for filtering purposes.
       
    52  * 
       
    53  * _TSLOG_RDEBUG    : When defined tracing instead of file logging. 
       
    54  *                    Default is for file logging.
       
    55  * 
       
    56  * --------------------------------------------------------------------------
       
    57  * 
       
    58  * USING LOGGING:
       
    59  * 
       
    60  * Basically the use is simple, register function use with TSLOG_CONTEXT, 
       
    61  * then log function enter by any TSLOG_IN -macro, then possibly use TSLOG
       
    62  * -macros for function logging and finally TSLOG_OUT -macros for returning
       
    63  * from the function.
       
    64  * 
       
    65  * @code
       
    66  * TInt CGood::Example( TInt aSomething )
       
    67  *     {
       
    68  *     // Create log context class, which is maintained for lifetime of the 
       
    69  *     // method. 
       
    70  *     TSLOG_CONTEXT( Example, TSLOG_LOCAL );
       
    71  * 
       
    72  *     // Indicate we are entering the function. 
       
    73  *     TSLOG_IN1( "aSomething contains value %d", aSomething );
       
    74  * 
       
    75  *     // Your buggy code...
       
    76  * 
       
    77  *     // Before leaving, indicate function execution has ended.
       
    78  *     TSLOG_OUT();
       
    79  * 
       
    80  *     return 0;
       
    81  *     }
       
    82  * @/code
       
    83  */
       
    84 
       
    85 #include <e32def.h>
       
    86 #include <e32std.h>
       
    87 
       
    88 #include "tslogutils.h"
       
    89 
       
    90 #define TSLOG_API 0
       
    91 #define TSLOG_LOCAL 1
       
    92 
       
    93 #define TSLOG_INFO 0
       
    94 #define TSLOG_WARNING 1
       
    95 #define TSLOG_ERROR 2
       
    96 
       
    97 #define TSLOG_ASSERT(_assertion)  __TSLOG_ASSERT_DBG(_assertion) 
       
    98 #define TSLOG_TRACE_ASSERT(_assertion) __ASSERT_DEBUG((_assertion), User::Invariant() )
       
    99 
       
   100 #ifdef _DEBUG
       
   101             
       
   102 /*****************************************************************************
       
   103  LOGGING MACROS - LOGGING ON
       
   104 *****************************************************************************/             
       
   105 
       
   106     /** 
       
   107      * Context initialization 
       
   108      * NOTE: TSLOG_STATIC_CONTEXT is meant for static methods.
       
   109      * 
       
   110      * @param _fn   Name of the function.
       
   111      * @param _vis  Visibility for the client, use values TSLOG_API or TSLOG_LOCAL
       
   112      * @param _thdId For static functions, thread id can be given here.
       
   113      */
       
   114     #define TSLOG_CONTEXT(_fn, _vis ) _TTsLogContext _dc((TText*)L ## #_fn, _TSLOG_LOG_COMPONENT_ID, _vis, (TUint)this, RProcess().SecureId().iId )
       
   115     #define TSLOG_STATIC_CONTEXT(_fn, _vis, _thdId) _TTsLogContext _dc((TText*)L ## #_fn, _TSLOG_LOG_COMPONENT_ID, _vis, _thdId, RProcess().SecureId().iId )
       
   116 
       
   117     /** 
       
   118      * Entering function 
       
   119      * 
       
   120      * @param string    Custom text. Example: TSLOG_IN0( "Yeah!!!" );
       
   121      * @param p1 - p5   For multiple variables in same string.
       
   122      */
       
   123     #define TSLOG_IN() do { _CHK_MULTIIN(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s "), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_ENTRY(); } while(0)
       
   124     #define TSLOG0_IN(string) do { _CHK_MULTIIN(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_ENTRY(); } while(0)
       
   125     #define TSLOG1_IN(string, p1) do { _CHK_MULTIIN(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1); _MARK_ENTRY(); } while(0)
       
   126     #define TSLOG2_IN(string, p1, p2) do { _CHK_MULTIIN(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2); _MARK_ENTRY(); } while(0)
       
   127     #define TSLOG3_IN(string, p1, p2, p3) do { _CHK_MULTIIN(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3); _MARK_ENTRY(); } while(0)
       
   128     #define TSLOG4_IN(string, p1, p2, p3, p4) do { _CHK_MULTIIN(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4); _MARK_ENTRY(); } while(0)
       
   129     #define TSLOG5_IN(string, p1, p2, p3, p4, p5) do { _CHK_MULTIIN(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4, p5); _MARK_ENTRY(); } while(0)
       
   130 
       
   131     /** Leaving function */
       
   132     #define TSLOG_OUT() do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s "), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_EXIT(); } while(0)
       
   133     #define TSLOG0_OUT(string) do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_EXIT(); } while(0)
       
   134     #define TSLOG1_OUT(string, p1) do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1); _MARK_EXIT(); } while(0)
       
   135     #define TSLOG2_OUT(string, p1, p2) do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2); _MARK_EXIT(); } while(0)
       
   136     #define TSLOG3_OUT(string, p1, p2, p3) do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3); _MARK_EXIT(); } while(0)
       
   137     #define TSLOG4_OUT(string, p1, p2, p3, p4) do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4); _MARK_EXIT(); } while(0)
       
   138     #define TSLOG5_OUT(string, p1, p2, p3, p4, p5) do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4, p5); _MARK_EXIT(); } while(0)
       
   139 
       
   140     /** Leaving function with return value */
       
   141     #define TSLOG0_RET(val, fmtstr) do { do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val); _MARK_EXIT(); } while(0); return val;} while(0)
       
   142     #define TSLOG1_RET(val, fmtstr, p1) do { do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1); _MARK_EXIT(); } while(0); return val;} while(0)
       
   143     #define TSLOG2_RET(val, fmtstr, p1, p2) do { do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2); _MARK_EXIT(); } while(0); return val;} while(0)
       
   144     #define TSLOG3_RET(val, fmtstr, p1, p2, p3) do { do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2, p3); _MARK_EXIT(); } while(0); return val;} while(0)
       
   145     #define TSLOG4_RET(val, fmtstr, p1, p2, p3, p4) do { do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2, p3, p4); _MARK_EXIT(); } while(0); return val;} while(0)
       
   146     #define TSLOG5_RET(val, fmtstr, p1, p2, p3, p4, p5) do { do { _DOINCHK(); _CHK_MULTIOUT(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2, p3, p4, p5); _MARK_EXIT(); } while(0); return val;} while(0)
       
   147 
       
   148     /** 
       
   149      * General log lines 
       
   150      * 
       
   151      * @param level     This can be used as internal information 
       
   152      *                  field, such as info, error, warning etc.
       
   153      * @param string    Custom string
       
   154      * @param p1 - p5   For multiple variables in same string.
       
   155      */
       
   156     #define TSLOG0(level, string) do { _DOINCHK(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); } while(0)
       
   157     #define TSLOG1(level, string, p1) do { _DOINCHK(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1); } while(0)
       
   158     #define TSLOG2(level, string, p1, p2) do { _DOINCHK(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2); } while(0)
       
   159     #define TSLOG3(level, string, p1, p2, p3) do { _DOINCHK(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3); } while(0)
       
   160     #define TSLOG4(level, string, p1, p2, p3, p4) do { _DOINCHK(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4); } while(0)
       
   161     #define TSLOG5(level, string, p1, p2, p3, p4, p5) do { _DOINCHK(); _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4, p5); } while(0)
       
   162 
       
   163     /** Error logging */
       
   164     #define __TSLOG_ASSERT_DBG( _assertion ) do { if( _assertion ) { break; } TFileName file; file.Copy( _L8( __FILE__ ) );   _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s Assert:%S:%d:" L ## #_assertion) , _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, &file, __LINE__ ); User::Invariant(); } while( 0 )
       
   165     #define __TSLOG_TRACE_ASSERT_DBG(_assertion, _textToPrint, _panicCode)  do { if (_assertion) { break; } _TSLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s ASSERTION FAILED!!! %s file: %s, line: %s"), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, _textToPrint, __FILE__, __LINE__); User::Panic(_L("AssertionFailed"), _panicCode} while(0)
       
   166     #define TSLOG_TRAPHANDLER() _TTsLogTrapHandler _traceTrapHandler; _traceTrapHandler.oldHandler = User::SetTrapHandler(&_traceTrapHandler)
       
   167 
       
   168 /*****************************************************************************
       
   169  LOGGING MACROS - NO LOGGING
       
   170 *****************************************************************************/ 
       
   171 #else // _DEBUG
       
   172 
       
   173     #define TSLOG_CONTEXT(_fn, _vis )
       
   174     #define TSLOG_STATIC_CONTEXT(_fn, _vis, _thdId)
       
   175 
       
   176     #define TSLOG_IN()
       
   177     #define TSLOG0_IN(string)
       
   178     #define TSLOG1_IN(string, p1)
       
   179     #define TSLOG2_IN(string, p1, p2)
       
   180     #define TSLOG3_IN(string, p1, p2, p3)
       
   181     #define TSLOG4_IN(string, p1, p2, p3, p4)
       
   182     #define TSLOG5_IN(string, p1, p2, p3, p4, p5)
       
   183 
       
   184     #define TSLOG_OUT()
       
   185     #define TSLOG0_OUT(string)
       
   186     #define TSLOG1_OUT(string, p1)
       
   187     #define TSLOG2_OUT(string, p1, p2)
       
   188     #define TSLOG3_OUT(string, p1, p2, p3)
       
   189     #define TSLOG4_OUT(string, p1, p2, p3, p4)
       
   190     #define TSLOG5_OUT(string, p1, p2, p3, p4, p5)
       
   191 
       
   192     #define TSLOG0_RET(val, fmtstr) return val
       
   193     #define TSLOG1_RET(val, fmtstr, p1) return val
       
   194     #define TSLOG2_RET(val, fmtstr, p1, p2) return val
       
   195     #define TSLOG3_RET(val, fmtstr, p1, p2, p3) return val
       
   196     #define TSLOG4_RET(val, fmtstr, p1, p2, p3, p4) return val
       
   197     #define TSLOG5_RET(val, fmtstr, p1, p2, p3, p4, p5) return val
       
   198 
       
   199     #define TSLOG0(level, string)
       
   200     #define TSLOG1(level, string, p1)
       
   201     #define TSLOG2(level, string, p1, p2)
       
   202     #define TSLOG3(level, string, p1, p2, p3)
       
   203     #define TSLOG4(level, string, p1, p2, p3, p4)
       
   204     #define TSLOG5(level, string, p1, p2, p3, p4, p5)
       
   205     
       
   206     #define BIND_TRACE_TRAPHANDLER()
       
   207     #define TRACE_DECL() TInt _iTraceThreadId
       
   208     #define TRACE_FAST_CREATE(_thdId) _thdId++;
       
   209     #define TRACE_CREATE()
       
   210 
       
   211     #define __TSLOG_ASSERT_DBG(_assertion)
       
   212     #define __TRACE_ASSERT_DBG(_assertion, _message, _panicCode )
       
   213 
       
   214 #endif // _DEBUG
       
   215 
       
   216 #endif      // TSLOGLOGUTILS_H
       
   217             
       
   218 // End of File