mobilemessaging/smilui/playerinc/SmilPlayerLogging.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-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:  
       
    15 *     Contains logging macros for SmilUi. Logging can be enabled from mmp file.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // ========== LOGGING MACROS ===============================
       
    22 
       
    23 #ifndef SMILPLAYERLOGGING_H
       
    24 #define SMILPLAYERLOGGING_H
       
    25 
       
    26 #ifdef USE_LOGGER
       
    27 
       
    28 #include <e32std.h>
       
    29 #include <e32def.h>
       
    30 #include <flogger.h>
       
    31 
       
    32 /*  logging macros usage:
       
    33 
       
    34 // replace SMILPLAYER with your own TLA (Three Letter Acronyme).
       
    35 
       
    36 // set logging on in mmp file...
       
    37 MACRO USE_LOGGER
       
    38 #ifdef WINS
       
    39 MACRO USE_RDEBUG
       
    40 #endif
       
    41 
       
    42 
       
    43 void CTestAppUi::ConstructL()
       
    44 {
       
    45     // creates log directory and log file on app startup.
       
    46     // prints starting banner...
       
    47     SMILPLAYERLOGGER_CREATE(iFs);
       
    48 
       
    49     // entering to function...
       
    50     SMILPLAYERLOGGER_ENTERFN("ConstructL()");
       
    51 
       
    52     TInt number = 42;
       
    53     TFileName file;
       
    54     file = "something" ....
       
    55 
       
    56     // print variable number of parameters...
       
    57     // Note: use _L macro for format string!
       
    58     SMILPLAYERLOGGER_WRITEF(_L("SMILPLAYER: number = %d, file = %S"), number, &file);
       
    59 
       
    60     // print just a string (no _L macro here!)
       
    61     SMILPLAYERLOGGER_WRITE("Hello world!");
       
    62 
       
    63     // leave from function...
       
    64     SMILPLAYERLOGGER_LEAVEFN("ConstructL()");
       
    65 }
       
    66 
       
    67 CTestAppUi::~CTestAppUi()
       
    68 {
       
    69     // print app exit banner when application exits.
       
    70     SMILPLAYERLOGGER_DELETE;
       
    71 }
       
    72 
       
    73 */
       
    74 
       
    75 #ifdef USE_RDEBUG
       
    76 
       
    77 _LIT(KSMILPLAYERLogBanner,             "SMILPLAYER");
       
    78 _LIT(KSMILPLAYERLogEnterFn,            "SMILPLAYER: >> %S");
       
    79 _LIT(KSMILPLAYERLogLeaveFn,            "SMILPLAYER: << %S");
       
    80 _LIT(KSMILPLAYERLogWrite,              "SMILPLAYER: %S");
       
    81 _LIT(KSMILPLAYERLogTag,                "SMILPLAYER: ");
       
    82 _LIT(KSMILPLAYERLogExit,               "SMILPLAYER: Application exit");
       
    83 _LIT(KSMILPLAYERLogTimeFormatString,   "%H:%T:%S:%*C2      ");
       
    84 
       
    85 #define SMILPLAYERLOGGER_CREATE(a)          {RDebug::Print(KSMILPLAYERLogBanner);}
       
    86 #define SMILPLAYERLOGGER_DELETE             {RDebug::Print(KSMILPLAYERLogExit);}
       
    87 #define SMILPLAYERLOGGER_ENTERFN(a)         {_LIT(temp, a); RDebug::Print(KSMILPLAYERLogEnterFn, &temp);}
       
    88 #define SMILPLAYERLOGGER_LEAVEFN(a)         {_LIT(temp, a); RDebug::Print(KSMILPLAYERLogLeaveFn, &temp);}
       
    89 #define SMILPLAYERLOGGER_WRITE(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL( buffer, KSMILPLAYERLogTimeFormatString );buffer.Append(temp); buffer.Insert(0, KSMILPLAYERLogTag); RDebug::Print(buffer); }
       
    90 //#define SMILPLAYERLOGGER_WRITE(a)           {_LIT(temp, a); RDebug::Print(KSMILPLAYERLogWrite, &temp);}
       
    91 #define SMILPLAYERLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL( buffer, KSMILPLAYERLogTimeFormatString ); buffer.Insert(0, temp); buffer.Insert(0, KSMILPLAYERLogTag); RDebug::Print(buffer); }
       
    92 #define SMILPLAYERLOGGER_WRITEF             RDebug::Print
       
    93 
       
    94 #else
       
    95 
       
    96 _LIT( KSMILPLAYERLogDir,               "smilui");
       
    97 _LIT( KSMILPLAYERLogFile,              "smilui.txt");
       
    98 _LIT8(KSMILPLAYERLogBanner,            "SMILPLAYER");
       
    99 _LIT8(KSMILPLAYERLogEnterFn,           "SMILPLAYER: >> %S");
       
   100 _LIT8(KSMILPLAYERLogLeaveFn,           "SMILPLAYER: << %S");
       
   101 _LIT8(KSMILPLAYERLogExit,              "SMILPLAYER: Application exit");
       
   102 _LIT( KSMILPLAYERLogTimeFormatString,  "%H:%T:%S:%*C2      ");
       
   103 
       
   104 #define SMILPLAYERLOGGER_CREATE(a)          {FCreate(a);}
       
   105 #define SMILPLAYERLOGGER_DELETE             {RFileLogger::Write(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, KSMILPLAYERLogExit);}
       
   106 #define SMILPLAYERLOGGER_ENTERFN(a)         {_LIT8(temp, a); RFileLogger::WriteFormat(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, KSMILPLAYERLogEnterFn, &temp);}
       
   107 #define SMILPLAYERLOGGER_LEAVEFN(a)         {_LIT8(temp, a); RFileLogger::WriteFormat(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, KSMILPLAYERLogLeaveFn, &temp);}
       
   108 #define SMILPLAYERLOGGER_WRITE(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL( buffer, KSMILPLAYERLogTimeFormatString ); buffer.Append(temp); RFileLogger::Write(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, buffer); }
       
   109 //#define SMILPLAYERLOGGER_WRITE(a)           {_LIT(temp, a); RFileLogger::Write(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, temp);}
       
   110 #define SMILPLAYERLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL( buffer, KSMILPLAYERLogTimeFormatString ); buffer.Insert(0, temp); RFileLogger::Write(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, buffer); }
       
   111 #define SMILPLAYERLOGGER_WRITEF             FPrint
       
   112 
       
   113 inline void FPrint(const TRefByValue<const TDesC> aFmt, ...)
       
   114 {
       
   115     VA_LIST list;
       
   116     VA_START(list,aFmt);
       
   117     RFileLogger::WriteFormat(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, aFmt, list);
       
   118 }
       
   119 
       
   120 inline void FPrint(const TDesC& aDes)
       
   121 {
       
   122     RFileLogger::WriteFormat(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, aDes);
       
   123 }
       
   124 
       
   125 inline void FHex(const TUint8* aPtr, TInt aLen)
       
   126 {
       
   127     RFileLogger::HexDump(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeAppend, 0, 0, aPtr, aLen);
       
   128 }
       
   129 
       
   130 inline void FHex(const TDesC8& aDes)
       
   131 {
       
   132     FHex(aDes.Ptr(), aDes.Length());
       
   133 }
       
   134 
       
   135 inline void FCreate(RFs& aFs)
       
   136 {
       
   137     TFileName path(_L("c:\\logs\\"));
       
   138     path.Append(KSMILPLAYERLogDir);
       
   139     path.Append(_L("\\"));
       
   140     aFs.MkDirAll(path);
       
   141     RFileLogger::WriteFormat(KSMILPLAYERLogDir, KSMILPLAYERLogFile, EFileLoggingModeOverwrite, KSMILPLAYERLogBanner);
       
   142 }
       
   143 
       
   144 #endif // USE_RDEBUG
       
   145 
       
   146 #else // USE_LOGGER
       
   147 
       
   148 // dummy inline FPrint for SMILPLAYERLOGGER_WRITEF macro.
       
   149 inline TInt FPrint(const TRefByValue<const TDesC> /*aFmt*/, ...) { return 0; }
       
   150 
       
   151 #define SMILPLAYERLOGGER_CREATE(a)
       
   152 #define SMILPLAYERLOGGER_DELETE
       
   153 #define SMILPLAYERLOGGER_ENTERFN(a)
       
   154 #define SMILPLAYERLOGGER_LEAVEFN(a)
       
   155 #define SMILPLAYERLOGGER_WRITE(a)
       
   156 // if USE_LOGGER not defined this call to FPrint gets optimized away.
       
   157 #define SMILPLAYERLOGGER_WRITEF 1 ? 0 : FPrint
       
   158 #define SMILPLAYERLOGGER_WRITE_TIMESTAMP(a)
       
   159 
       
   160 #endif // USE_LOGGER
       
   161 
       
   162 #endif // SMILPLAYERLOGGING_H
       
   163 
       
   164 // =========================================================