upnpframework/inc/upnplog.h
changeset 0 7f85d04be362
child 38 5360b7ddc251
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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:  log/assert facility of upnp framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // **************************************************************************
       
    20 // *
       
    21 // *  HOW TO USE THIS LOGGING FACILITY
       
    22 // *
       
    23 // * 1. enable log facility in the code.
       
    24 // *     _LIT( KComponentLogfile, "component.txt");
       
    25 // *     #include "upnplog.h"
       
    26 // *
       
    27 // * 2. have flogger in mmp-file
       
    28 // *     DEBUGLIBRARY FLOGGER.LIB
       
    29 // *
       
    30 // * 3. use the log interface in the source
       
    31 // *     __LOG( char* strz )
       
    32 // *     __LOG1( char* strz, p1 )
       
    33 // *     __LOG2( char* strz, p1, p2 )
       
    34 // *     __LOG3( char* strz, p1, p2, p3 )
       
    35 // *     __LOG8( const TDesC8& msg )
       
    36 // *     __LOG16( const TDesC16& msg )
       
    37 // *     __ASSERTD( test, file, line )
       
    38 // *     __ASSERT( test, file, line )
       
    39 // *     __PANICD( file, line )
       
    40 // *     __PANIC( file, line )
       
    41 // *
       
    42 // * 4. The default logging/assertion modes are following:
       
    43 // *     DEBUG build:    log to console, assertion mode on.
       
    44 // *     RELEASE build:  log turned off, assertion mode off.
       
    45 // *     To override this preset, you can use following macros:
       
    46 // *     MACRO __UPNP_LOG_FILE          (logging to file)
       
    47 // *     MACRO __UPNP_LOG_CONSOLE       (logging to console)
       
    48 // *     MACRO __UPNP_LOG_OFF           (logging turned off in DEBUG build)
       
    49 // *     MACRO __UPNP_DEBUG_ASSERT      (enable D-panic and D-assert)
       
    50 // *     MACRO __UPNP_DEBUG_ASSERT_OFF  (disable D-panic and D-assert)
       
    51 // *     in case of using logging in RELEASE build, remember to switch
       
    52 // *     LIBRARY FLOGGER.LIB instead of DEBUGLIBRARY.
       
    53 // *
       
    54 // **************************************************************************
       
    55 
       
    56 
       
    57 #ifndef __UPNPLOG_H__
       
    58 #define __UPNPLOG_H__
       
    59 
       
    60 
       
    61 #include <e32std.h>
       
    62 
       
    63 
       
    64 // in DEBUG build activate the default modes
       
    65 #ifdef _DEBUG
       
    66 
       
    67     #if !( defined(__UPNP_LOG_FILE) || \
       
    68         defined(__UPNP_LOG_CONSOLE) || \
       
    69         defined(__UPNP_LOG_OFF) )
       
    70         // activate default logging mode
       
    71         #define __UPNP_LOG_CONSOLE
       
    72     #endif
       
    73 
       
    74     #if !( defined(__UPNP_DEBUG_ASSERT) || \
       
    75         defined(__UPNP_DEBUG_ASSERT_OFF) )
       
    76         // activate debug assertion mode
       
    77         #define __UPNP_DEBUG_ASSERT
       
    78     #endif
       
    79 
       
    80 #endif //_DEBUG
       
    81 
       
    82 
       
    83 // this dummy function is to avoid compiler warning #177-D:
       
    84 // variable was declared but never referenced
       
    85 inline void __Dummy_KComponentLogfile()
       
    86     {
       
    87     TUint16 c = KComponentLogfile().Size();
       
    88     c = 0;
       
    89     }
       
    90 
       
    91 //
       
    92 // **************************************************************************
       
    93 // LOGGING MACROS
       
    94 // **************************************************************************
       
    95 //
       
    96 
       
    97 #if defined(__UPNP_LOG_FILE)
       
    98 
       
    99     #include <flogger.h>
       
   100 
       
   101     // Subdirectory under c:\logs -directory
       
   102     _LIT( KLogDir, "upnpframework" );
       
   103 
       
   104     #define __LOG( strz ) Print16(_L(strz))
       
   105     #define __LOG1( strz,p1 ) Print16(_L(strz),p1)
       
   106     #define __LOG2( strz,p1,p2 ) Print16(_L(strz),p1,p2)
       
   107     #define __LOG3( strz,p1,p2,p3 ) \
       
   108         Print16(_L(strz),p1,p2,p3)
       
   109     #define __LOG8( msg ) Print8( _L8( "%S" ), &msg )
       
   110     #define __LOG16( msg ) Print16( _L16( "%S" ), &msg )
       
   111     #define __LOG8_1( strz,p1 ) Print8(_L8(strz),p1)
       
   112 
       
   113     // Writes a log text to a file using file logger
       
   114     inline void Print16( const TRefByValue<const TDesC> aFmt, ... )
       
   115         {
       
   116         VA_LIST list;
       
   117         VA_START(list,aFmt);
       
   118         RFileLogger::WriteFormat( KLogDir, KComponentLogfile,
       
   119             EFileLoggingModeAppend, aFmt, list );
       
   120         VA_END( list );
       
   121         }    
       
   122 
       
   123         // Writes a log text to a file using file logger
       
   124     inline void Print8( const TRefByValue<const TDesC8> aFmt, ... )
       
   125         {
       
   126         VA_LIST list;
       
   127         VA_START(list,aFmt);
       
   128         RFileLogger::WriteFormat( KLogDir, KComponentLogfile,
       
   129             EFileLoggingModeAppend, aFmt, list );
       
   130         VA_END( list );
       
   131         }
       
   132 
       
   133 #elif defined(__UPNP_LOG_CONSOLE)
       
   134 
       
   135     #include <f32file.h>
       
   136 
       
   137     #define __LOG( strz ) RDebug::Print(_L(strz))
       
   138     #define __LOG1( strz,p1 ) RDebug::Print(_L(strz),p1)
       
   139     #define __LOG2( strz,p1,p2 ) RDebug::Print(_L(strz),p1,p2)
       
   140     #define __LOG3( strz,p1,p2,p3 ) \
       
   141         RDebug::Print(_L(strz),p1,p2,p3)
       
   142     #define __LOG8( msg ) Debug8(msg)
       
   143     #define __LOG16( msg ) RDebug::Print(msg)
       
   144     #define __LOG8_1( strz,p1 ) RDebug::Printf(strz, p1)
       
   145 
       
   146     inline void Debug8( const TDesC8& aMsg )
       
   147         {
       
   148         __Dummy_KComponentLogfile();
       
   149         RDebug::RawPrint( aMsg );
       
   150         }
       
   151 
       
   152 #else // __UPNP_LOG_OFF
       
   153 
       
   154     #define __LOG( strz ) __Dummy_KComponentLogfile();
       
   155     #define __LOG1( fmt,p1 ) __Dummy_KComponentLogfile();
       
   156     #define __LOG2( fmt,p1,p2 ) __Dummy_KComponentLogfile();
       
   157     #define __LOG3( fmt,p1,p2,p3 ) __Dummy_KComponentLogfile();
       
   158     #define __LOG8( msg ) __Dummy_KComponentLogfile();
       
   159     #define __LOG16( msg ) __Dummy_KComponentLogfile();
       
   160     #define __LOG8_1( strz,p1 ) __Dummy_KComponentLogfile();
       
   161 
       
   162 #endif // __UPNP_LOG_FILE || __UPNP_LOG_CONSOLE || __UPNP_LOG_OFF
       
   163 
       
   164 
       
   165 //
       
   166 // **************************************************************************
       
   167 // ASSERTION MACROS
       
   168 // **************************************************************************
       
   169 //
       
   170 
       
   171 #define __ASSERT( test, file, line ) \
       
   172     if( !( test ) ) \
       
   173         { \
       
   174         __LOG2( "Assertion failed: %s %d", \
       
   175             file, line ); \
       
   176         User::Panic( _L(file), line ); \
       
   177         }
       
   178 
       
   179 #define __PANIC( file, line ) \
       
   180     { \
       
   181     __LOG2( "Panic: %s %d", \
       
   182         file, line ); \
       
   183     User::Panic( _L(file), line ) \
       
   184     }
       
   185 
       
   186 #ifdef __UPNP_DEBUG_ASSERT
       
   187 
       
   188     #define __ASSERTD( test, file, line ) \
       
   189         if( !( test ) ) \
       
   190             { \
       
   191             __LOG2( "Assertion failed: %s %d", \
       
   192                 file, line ); \
       
   193             User::Panic( _L(file), line ); \
       
   194             }
       
   195 
       
   196     #define __PANICD( file, line ) \
       
   197         { \
       
   198         __LOG2( "Panic: %s %d", \
       
   199             file, line ); \
       
   200         User::Panic( _L(file), line ); \
       
   201         }
       
   202 
       
   203 #else // __UPNP_DEBUG_ASSERT_OFF
       
   204 
       
   205     #define __ASSERTD( test, file, line )
       
   206     #define __PANICD( file, line )
       
   207 
       
   208 #endif // __UPNP_DEBUG_ASSERT || __UPNP_DEBUG_ASSERT_OFF
       
   209 
       
   210 
       
   211 
       
   212 #endif // __UPNPLOG_H__
       
   213