mediator/inc/Common/Debug.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Common trace-information file.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef DEBUG_H
       
    20 #define DEBUG_H
       
    21 
       
    22 /**
       
    23  *  NOTE: Link to flogger.lib in MMP file. Use DEBUGLIBRARY -keyword to avoid
       
    24  *        warnings in release builds.
       
    25  *        Example:  DEBUGLIBRARY    flogger.lib
       
    26  */
       
    27 
       
    28 /**
       
    29  *  Usage:  LOG(_L("[MODULE_NAME]\t Trace text here"));
       
    30  *          TRACE(Print(_L("[MODULE_NAME]\t Trace text here with parameter %d"), iCount));
       
    31  *
       
    32  *          Trace target can be changed below (file logging needs directory c:\logs\upnp)
       
    33  *          #define __FLOGGING -row uncommented (default)  = File logging
       
    34  *          #define __CLOGGING -row uncommented            = Console logging
       
    35  */
       
    36 
       
    37 // undefine for sure
       
    38 #undef __FLOGGING__
       
    39 #undef __CLOGGING__
       
    40 
       
    41 
       
    42 // Remove comments to get module internal logss
       
    43 #ifdef _DEBUG
       
    44 
       
    45 // Uncomment this in order to get more data than just errors
       
    46 //#define _DEBUG_MEDIATOR
       
    47 
       
    48 // Uncomment this to get memory allocation prints from module
       
    49 //#define MEMORY_PRINT
       
    50 
       
    51 // Define one of these flags:
       
    52 // FLOGGING = File logging
       
    53 // CLOGGING = Console logging
       
    54 //#define __FLOGGING__
       
    55 #define __CLOGGING__
       
    56 
       
    57 #endif
       
    58 
       
    59 
       
    60 
       
    61 // Then actual definitions depending on the 
       
    62 // flag values.
       
    63 
       
    64 #ifdef _DEBUG
       
    65 
       
    66     #include <e32std.h>
       
    67 
       
    68     // Actual log file name
       
    69     _LIT(KLogFile,"MediatorServer.txt");
       
    70 
       
    71     // Subdirectory under c:\logs -directory
       
    72     _LIT(KLogDir, "MediatorServer");
       
    73 
       
    74     #include <f32file.h>
       
    75     #include <flogger.h>
       
    76 
       
    77 
       
    78     // Define the top level macros
       
    79     #ifdef _DEBUG_MEDIATOR 
       
    80         #ifdef MEMORY_PRINT
       
    81             #define LOG(a) {Print(a); MemPrint();}
       
    82             #define TRACE(a) {a; MemPrint();}
       
    83         #else // MEMORY_PRINT
       
    84             #define LOG(a) {Print(a);}
       
    85             #define TRACE(a) {a;}
       
    86         #endif // MEMORY_PRINT
       
    87     #else // _DEBUG_MEDIATOR
       
    88         // No logs in udeb-builds
       
    89         #define LOG(a)
       
    90         #define TRACE(a)
       
    91     #endif // _DEBUG_MEDIATOR        
       
    92     
       
    93     // Error logs and traces are always compiled in udeb-builds
       
    94     #ifdef MEMORY_PRINT
       
    95         #define ERROR_LOG(a) {Print(a); MemPrint();}
       
    96         #define ERROR_TRACE(a) {a; MemPrint();}
       
    97     #else // MEMORY_PRINT
       
    98         #define ERROR_LOG(a) {Print(a);}
       
    99         #define ERROR_TRACE(a) {a;}
       
   100     #endif // MEMORY_PRINT        
       
   101 
       
   102     inline void MemPrint()
       
   103         {
       
   104         TUint32 id = RThread().SecureId().iId;
       
   105         TInt allocSize = 0;
       
   106         User::Heap().AllocSize( allocSize );
       
   107         RDebug::Print(_L("[MEMORY] ID: %d\t AllocSize: %d"), id, allocSize );
       
   108         }
       
   109             
       
   110     #ifdef __FLOGGING__
       
   111 
       
   112         inline void Print(const TRefByValue<const TDesC> aFmt, ...)
       
   113             {
       
   114             VA_LIST list;
       
   115             VA_START(list,aFmt);
       
   116             TBuf<32> logFile(KLogFile);
       
   117             RFileLogger::WriteFormat(KLogDir, logFile, EFileLoggingModeAppend, aFmt, list);
       
   118             }
       
   119        
       
   120     #else
       
   121         // Console Logging on
       
   122         #define Print RDebug::Print
       
   123 
       
   124     #endif  // __FLOGGING__
       
   125 
       
   126 #else
       
   127 
       
   128     // DEBUG build is not on --> no logging at all
       
   129     #define LOG(a)
       
   130     #define TRACE(a)
       
   131     #define ERROR_LOG(a)
       
   132     #define ERROR_TRACE(a)
       
   133 
       
   134 #endif  // _DEBUG
       
   135 
       
   136 #endif      // DEBUG_H
       
   137             
       
   138 // End of File