upnpframework/inc/upnplogging.h
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Logging facility for UPnP framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // ***************************************************
       
    20 // * How to use UPnP framework logging facility
       
    21 // * 1. define KComponentLogfile
       
    22 // *     _LIT( KComponentLogfile, "AVControlServer.txt");
       
    23 // * 2. if you want, define one of these macros:
       
    24 // *     __FILE_LOGGING__     (logging to file)
       
    25 // *     __CONSOLE_LOGGING__  (logging to console)
       
    26 // * 3. have flogger in mmp-file
       
    27 // *     DEBUGLIBRARY FLOGGER.LIB
       
    28 // * 4. now you can use the log interface
       
    29 // *     __LOG( char* strz )
       
    30 // *     __LOG1( char* strz, p1 )
       
    31 // *     __LOG2( char* strz, p1, p2 )
       
    32 // *     __LOG3( char* strz, p1, p2, p3 )
       
    33 // *     __LOG8( const TDesC8& msg )
       
    34 // *     __LOG16( const TDesC16& msg )
       
    35 // ***************************************************
       
    36 
       
    37 
       
    38 #ifndef __UPNPLOGGING_H__
       
    39 #define __UPNPLOGGING_H__
       
    40 
       
    41 
       
    42 #include <e32std.h>
       
    43 
       
    44 
       
    45 #ifdef _DEBUG
       
    46   // activate default logging mode in debug builds
       
    47   #define __CONSOLE_LOGGING__
       
    48   //#define __FILE_LOGGING__
       
    49 #endif //_DEBUG
       
    50 
       
    51 
       
    52 
       
    53 #if defined(__CONSOLE_LOGGING__)
       
    54 
       
    55     #include <f32file.h>
       
    56 
       
    57     #define __LOG( strz ) RDebug::Print(_L(strz))
       
    58     #define __LOG1( strz,p1 ) RDebug::Print(_L(strz),p1)
       
    59     #define __LOG2( strz,p1,p2 ) RDebug::Print(_L(strz),p1,p2)
       
    60     #define __LOG3( strz,p1,p2,p3 ) \
       
    61         RDebug::Print(_L(strz),p1,p2,p3)
       
    62     #define __LOG8( msg ) Debug8(msg)
       
    63     #define __LOG16( msg ) RDebug::Print(msg)
       
    64     #define __LOG8_1( strz,p1 ) RDebug::Printf(strz, p1)
       
    65 
       
    66     inline void Debug8( const TDesC8& aMsg )
       
    67         {
       
    68         RDebug::RawPrint( aMsg );
       
    69         }
       
    70 
       
    71     inline void __Dummy_KComponentLogfile()
       
    72         {
       
    73         // this dummy function is to avoid compiler warning #177-D:
       
    74         // variable was declared but never referenced
       
    75         TUint16 c = KComponentLogfile()[0];
       
    76         c = 0;
       
    77         }
       
    78 
       
    79 #elif defined(__FILE_LOGGING__)
       
    80 
       
    81     #include <flogger.h>
       
    82 
       
    83     // Subdirectory under c:\logs -directory
       
    84     _LIT(KLogDir, "upnpframework");
       
    85 
       
    86     #define __LOG( strz ) Print16(_L(strz))
       
    87     #define __LOG1( strz,p1 ) Print16(_L(strz),p1)
       
    88     #define __LOG2( strz,p1,p2 ) Print16(_L(strz),p1,p2)
       
    89     #define __LOG3( strz,p1,p2,p3 ) \
       
    90         Print16(_L(strz),p1,p2,p3)
       
    91     #define __LOG8( msg ) Print8( _L8( "%S" ), &msg )
       
    92     #define __LOG16( msg ) Print16( _L16( "%S" ), &msg )
       
    93     #define __LOG8_1( strz,p1 ) Print8(_L8(strz),p1)
       
    94 
       
    95     // Writes a log text to a file using file logger
       
    96     inline void Print16( const TRefByValue<const TDesC> aFmt, ... )
       
    97         {
       
    98         VA_LIST list;
       
    99         VA_START(list,aFmt);
       
   100         RFileLogger::WriteFormat( KLogDir, KComponentLogfile,
       
   101             EFileLoggingModeAppend, aFmt, list );
       
   102         VA_END( list );
       
   103         }    
       
   104 
       
   105         // Writes a log text to a file using file logger
       
   106     inline void Print8( const TRefByValue<const TDesC8> aFmt, ... )
       
   107         {
       
   108         VA_LIST list;
       
   109         VA_START(list,aFmt);
       
   110         RFileLogger::WriteFormat( KLogDir, KComponentLogfile,
       
   111             EFileLoggingModeAppend, aFmt, list );
       
   112         VA_END( list );
       
   113         }
       
   114 
       
   115 #else // !(__CONSOLE_LOGGING__ | __FILE_LOGGING__)
       
   116 
       
   117     #define __LOG( strz )
       
   118     #define __LOG1( fmt,p1 )
       
   119     #define __LOG2( fmt,p1,p2 )
       
   120     #define __LOG3( fmt,p1,p2,p3 )
       
   121     #define __LOG8( msg )
       
   122     #define __LOG16( msg )
       
   123     #define __LOG8_1( strz,p1 )
       
   124 
       
   125 #endif // __CONSOLE_LOGGING__ | __FILE_LOGGING__
       
   126 
       
   127 
       
   128 #endif // __UPNPLOGGING_H__
       
   129