pkiutilities/CertmanUi/INC/CertManUILogger.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2003-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:   Implements logger functionality of the module
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CERTMANUI_LOGGER_H
       
    20 #define CERTMANUI_LOGGER_H
       
    21 
       
    22 
       
    23 #if defined ( _DEBUG ) || defined ( _CERTMANUI_LOG_ )
       
    24 
       
    25 // INCLUDES
       
    26 #include <flogger.h>
       
    27 
       
    28 enum TLoggingSelectors
       
    29   {
       
    30   ECertManUILogEnter = 1,
       
    31     ECertManUILogLeave,
       
    32     ECertManUILogTimeStamp,
       
    33     ECertManUILogWrite
       
    34   };
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // Macros to be substituted
       
    39 _LIT( KCertManUILogMessageAppBanner,   "CertManUI: module (%d.%d.%d) started" );
       
    40 _LIT( KCertManUILogExit,               "CertManUI: module exit" );
       
    41 _LIT( KCertManUILogTimeFormatString,   "%H:%T:%S:%*C3" );
       
    42 _LIT8( KCertManUILogEnterFn,           "ENTRY " );
       
    43 _LIT8( KCertManUILogLeaveFn,           "EXIT " );
       
    44 
       
    45 // ATTENTION!!! We're depending on FLogger DLL, because it presumes the
       
    46 // existance of C:\LOGS directory.
       
    47 _LIT( KCertManUIFLoggerDependency,    "c:\\logs\\" );
       
    48 _LIT( KCertManUIDoubleBackSlash,    "\\" );
       
    49 _LIT( KCertManUILogDir,         "certmanui" );
       
    50 _LIT( KCertManUILogFile,        "certmanui.log" );
       
    51 
       
    52 /**
       
    53 * Use this macro in order to initialize logger :
       
    54 * - create log directory,
       
    55 * - write version information into the log file
       
    56 */
       
    57 #define CERTMANUILOGGER_CREATE { \
       
    58                               TFileName path( KCertManUIFLoggerDependency ); \
       
    59                               path.Append( KCertManUILogDir ); \
       
    60                               path.Append( KCertManUIDoubleBackSlash ); \
       
    61                               RFs& fs = CEikonEnv::Static()->FsSession(); \
       
    62                               fs.MkDirAll( path ); \
       
    63                               RFileLogger::WriteFormat( \
       
    64                                                       KCertManUILogDir, \
       
    65                                                       KCertManUILogFile, \
       
    66                                                       EFileLoggingModeOverwrite, \
       
    67                                                       KCertManUILogMessageAppBanner \
       
    68                                                       ); \
       
    69                               }
       
    70 
       
    71 /**
       
    72 * Use this macro for writing information about exiting.
       
    73 */
       
    74 #define CERTMANUILOGGER_DELETE { \
       
    75                                 RFileLogger::Write( \
       
    76                                                   KCertManUILogDir, \
       
    77                                                   KCertManUILogFile, \
       
    78                                                   EFileLoggingModeAppend, \
       
    79                                                   KCertManUILogExit \
       
    80                                                   ); \
       
    81                                 }
       
    82 
       
    83 /**
       
    84 * Use this function at the entry point of any functions.
       
    85 * @param a Entry information of the method.
       
    86 */
       
    87 #define CERTMANUILOGGER_ENTERFN( a ) write_log (ECertManUILogEnter, a)
       
    88 /**
       
    89 * Use this function right before you leave the method.
       
    90 * @param a Leaving information of the method.
       
    91 */
       
    92 #define CERTMANUILOGGER_LEAVEFN( a ) write_log (ECertManUILogLeave, a)
       
    93 
       
    94 /**
       
    95 * Use this function at any points of a function for logging the current state.
       
    96 * @param a String to be written into logfile about the current state
       
    97 */
       
    98 #define LOG_WRITE( a ) write_log (ECertManUILogWrite, a)
       
    99 /**
       
   100 * Use this function at any points of a function for logging the current state.
       
   101 * You can use printf-like formats, but with only one parameter to be substituted..
       
   102 * @param a Format string,
       
   103 * @param b Parameter to be substituted.
       
   104 */
       
   105 #define LOG_WRITE_FORMAT( a, b ) write_log (ECertManUILogWrite, a, b)
       
   106 
       
   107 /**
       
   108 * Use this function at any points of a function for logging the current state.
       
   109 * The current date/time stamp is written besides the string you give.
       
   110 * @param a String to be written into logfile about the current state
       
   111 */
       
   112 
       
   113 #define CERTMANUILOGGER_WRITE_TIMESTAMP( a ) write_log (ECertManUILogTimeStamp, a)
       
   114 
       
   115 inline void write_log (TInt aSelector, const char* aFmt,...) //lint !e960
       
   116     {
       
   117     TBuf8<256> buf;
       
   118         {
       
   119       VA_LIST ap;//lint !e960
       
   120         TPtrC8 fmt((unsigned char *)aFmt);
       
   121       VA_START(ap, aFmt);  //lint !e960
       
   122       buf.FormatList(fmt, ap);
       
   123       VA_END(ap);  //lint !e960
       
   124         }
       
   125     switch(aSelector)
       
   126         {
       
   127         case ECertManUILogEnter:
       
   128             buf.Insert(0, KCertManUILogEnterFn);
       
   129             break;
       
   130         case ECertManUILogLeave:
       
   131             buf.Insert(0, KCertManUILogLeaveFn);
       
   132             break;
       
   133         default:
       
   134             break;
       
   135         }
       
   136 
       
   137     RFileLogger::Write( KCertManUILogDir, KCertManUILogFile, EFileLoggingModeAppend, buf);
       
   138 
       
   139     TBuf<256> tempBuf;
       
   140     tempBuf.Copy( buf );
       
   141     RDebug::Print( tempBuf );
       
   142     }
       
   143 
       
   144 #define LOG_HEXDUMP( aBuf ) { \
       
   145                             RFileLogger::HexDump( \
       
   146                                                   KCertManUILogDir, \
       
   147                                                   KCertManUILogFile, \
       
   148                                                   EFileLoggingModeAppend, \
       
   149                                                   ((const TText *)" "), \
       
   150                                                   ((const TText *)" "), \
       
   151                                                   aBuf.Ptr(), aBuf.Size()); \
       
   152                             }
       
   153 
       
   154 
       
   155 #else // _DEBUG || _CERTMANUI_LOG
       
   156 
       
   157 // Empty macros
       
   158 #define CERTMANUILOGGER_CREATE
       
   159 #define CERTMANUILOGGER_DELETE
       
   160 #define CERTMANUILOGGER_ENTERFN( a )
       
   161 #define CERTMANUILOGGER_LEAVEFN( a )
       
   162 #define LOG_WRITE( a )
       
   163 #define LOG_WRITE_FORMAT( a, b )
       
   164 #define CERTMANUILOGGER_WRITE_TIMESTAMP( a ) /**/
       
   165 
       
   166 #endif // _DEBUG || _CERTMANUI_LOG
       
   167 
       
   168 #endif  // CERTMANUI_LOGGER_H
       
   169 
       
   170 // End of file