inc/muslogger.h
changeset 0 f0cf47e981f9
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2006 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MUSLOGGER_H
       
    20 #define MUSLOGGER_H
       
    21 
       
    22 // Disabled PC_lint warning for "Undefined preprocessor variable 'UNIT_TESTING'"
       
    23 /*lint -e553 */
       
    24 #if ( !_DEBUG || UNIT_TESTING ) // release or unit test build; no logs
       
    25 
       
    26 #define MUS_LOG_TDESC( aPrefix, aString )
       
    27 #define MUS_LOG_TDESC8( aPrefix, aString )
       
    28 #define MUS_LOG( aFmt )
       
    29 #define MUS_LOG1( aFmt, aVar1 )
       
    30 #define MUS_LOG2( aFmt, aVar1, aVar2 )
       
    31 #define MUS_LOG3( aFmt, aVar1, aVar2, aVar3 )
       
    32 
       
    33 #else // debug build; logs
       
    34 
       
    35 #include <e32debug.h>
       
    36 #include <flogger.h>
       
    37 
       
    38 _LIT( KMusLogDir, "mus" );           // MultimediaSharing logging directory.
       
    39 _LIT( KMusLogFile, "musdebug.txt" ); // MultimediaSharing log file name.
       
    40 
       
    41 // File logging can be disabled by commenting above definition. 
       
    42 #define MUS_FILE_LOGGING_ENABLED
       
    43 
       
    44 #if ( defined __WINSCW__ ) || ( defined __WINS__ )
       
    45 // No sense to have file logging enabled in wins
       
    46 #undef MUS_FILE_LOGGING_ENABLED
       
    47 #endif
       
    48 
       
    49 #ifdef MUS_FILE_LOGGING_ENABLED
       
    50 const TBool KMusFileLoggingEnabled = ETrue;
       
    51 #else
       
    52 const TBool KMusFileLoggingEnabled = EFalse;
       
    53 #endif
       
    54 
       
    55 #define MUS_LOG_TDESC( aPrefix, aString )\
       
    56     {\
       
    57     _LIT( KLogPrefix, aPrefix );\
       
    58     HBufC* logString = HBufC::NewLC( KLogPrefix().Length()+\
       
    59                                      aString.Length() );\
       
    60     logString->Des().Append( KLogPrefix() );\
       
    61     logString->Des().Append( aString );\
       
    62     if ( KMusFileLoggingEnabled )\
       
    63         {\
       
    64         RFileLogger::Write( KMusLogDir, KMusLogFile,\
       
    65                               EFileLoggingModeAppend,\
       
    66                               *logString );\
       
    67         }\
       
    68     RDebug::Print( *logString );\
       
    69     CleanupStack::PopAndDestroy( logString );\
       
    70     }                                     
       
    71 
       
    72 #define MUS_LOG_TDESC8( aPrefix, aString )\
       
    73     {\
       
    74     _LIT8( KLogPrefix8, aPrefix );\
       
    75     HBufC8* logString8 = HBufC8::NewLC( KLogPrefix8().Length()+\
       
    76                                      aString.Length() );\
       
    77     logString8->Des().Append( KLogPrefix8() );\
       
    78     logString8->Des().Append( aString );\
       
    79     if ( KMusFileLoggingEnabled )\
       
    80         {\
       
    81         RFileLogger::Write( KMusLogDir, KMusLogFile,\
       
    82                               EFileLoggingModeAppend,\
       
    83                               *logString8 );\
       
    84         }\
       
    85     RDebug::RawPrint( *logString8 );\
       
    86     CleanupStack::PopAndDestroy( logString8 );\
       
    87     }    
       
    88 
       
    89 #define MUS_LOG( aFmt )\
       
    90     {\
       
    91     _LIT( KLogMsg, aFmt );\
       
    92     if ( KMusFileLoggingEnabled )\
       
    93         {\
       
    94         RFileLogger::WriteFormat( KMusLogDir, KMusLogFile,\
       
    95                                   EFileLoggingModeAppend,\
       
    96                                   KLogMsg() );\
       
    97         }\
       
    98     RDebug::Print( KLogMsg() );\
       
    99     }
       
   100 
       
   101 #define MUS_LOG1( aFmt, aVar1 )\
       
   102     {\
       
   103     _LIT( KLogMsg, aFmt );\
       
   104     if ( KMusFileLoggingEnabled )\
       
   105         {\
       
   106         RFileLogger::WriteFormat( KMusLogDir, KMusLogFile,\
       
   107                                   EFileLoggingModeAppend,\
       
   108                                   KLogMsg(), aVar1 );\
       
   109         }\
       
   110     RDebug::Print( KLogMsg(), aVar1 );\
       
   111     }
       
   112 
       
   113 #define MUS_LOG2( aFmt, aVar1, aVar2 )\
       
   114     {\
       
   115     _LIT( KLogMsg, aFmt );\
       
   116     if ( KMusFileLoggingEnabled )\
       
   117         {\
       
   118         RFileLogger::WriteFormat( KMusLogDir, KMusLogFile,\
       
   119                               EFileLoggingModeAppend,\
       
   120                               KLogMsg(), aVar1, aVar2 );\
       
   121         }\
       
   122     RDebug::Print( KLogMsg(), aVar1, aVar2 );\
       
   123     }
       
   124 
       
   125 #define MUS_LOG3( aFmt, aVar1, aVar2, aVar3 )\
       
   126     {\
       
   127     _LIT( KLogMsg, aFmt );\
       
   128     if ( KMusFileLoggingEnabled )\
       
   129         {\
       
   130         RFileLogger::WriteFormat( KMusLogDir, KMusLogFile,\
       
   131                               EFileLoggingModeAppend,\
       
   132                               KLogMsg(), aVar1, aVar2, aVar3 );\
       
   133         }\
       
   134     RDebug::Print( KLogMsg(), aVar1, aVar2, aVar3 );\
       
   135     }
       
   136  
       
   137 #endif
       
   138 
       
   139 #define LEAVE_IF_NOT( x, y ) \
       
   140     if( x != y && x != KErrNone )\
       
   141         {\
       
   142         MUS_LOG1( "mus: [      ]     Leaving with code %d", x )\
       
   143         User::Leave( x );\
       
   144         }
       
   145 
       
   146 #endif // MUSLOGGER_H
       
   147 
       
   148 // End of File