pkiutilities/SecModUI/inc/SecModUILogger.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     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:   Implements logger functionality of the module
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef SECMODUI_LOGGER_H
       
    21 #define SECMODUI_LOGGER_H
       
    22 
       
    23 
       
    24 #if defined ( _DEBUG ) || defined ( _SECMODUI_LOG_ )
       
    25 
       
    26 // INCLUDES
       
    27 #include <flogger.h>
       
    28 #include <e32debug.h>
       
    29 
       
    30 enum TLoggingSelectors
       
    31 	{ 
       
    32 	EEnterFunction = 1,
       
    33     ELeaveFunction,
       
    34     EWriteLog
       
    35 	};
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 // Macros to be substituted
       
    40 _LIT( KLogMessageAppBanner,   "SecModUI: module (%d.%d.%d) started" );
       
    41 _LIT( KLogExit,               "SecModUI: module exit" );
       
    42 _LIT( KLogTimeFormatString,   "%H:%T:%S:%*C3" );
       
    43 _LIT8( KLogEnterFn,           "ENTRY " );
       
    44 _LIT8( KLogLeaveFn,           "EXIT " );
       
    45 
       
    46 // ATTENTION!!! We're depending on FLogger DLL, because it presumes the
       
    47 // existance of C:\LOGS directory.
       
    48 _LIT( KFLoggerDependency,		"c:\\logs\\" );
       
    49 _LIT( KDoubleBackSlash,		    "\\" );
       
    50 _LIT( KLogDir,					"SecModUI" );
       
    51 _LIT( KLogFile,				    "SecModUI.log" );
       
    52 
       
    53 /**
       
    54 * Use this macro in order to initialize logger :
       
    55 * - create log directory,
       
    56 * - write version information into the log file
       
    57 */
       
    58 #define LOG_CREATE  { TFileName path( KFLoggerDependency );  \
       
    59     path.Append( KLogDir ); path.Append( KDoubleBackSlash ); \
       
    60     RFs& fs = CEikonEnv::Static()->FsSession(); fs.MkDirAll( path ); \
       
    61     RFileLogger::WriteFormat( \
       
    62         KLogDir, KLogFile, EFileLoggingModeOverwrite, KLogMessageAppBanner ); }
       
    63 
       
    64 /**
       
    65 * Use this macro for writing information about exiting.
       
    66 */
       
    67 #define LOG_DELETE { \
       
    68     RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, KLogExit ); }
       
    69 
       
    70 /**
       
    71 * Use this function at the entry point of any functions.
       
    72 * @param a Entry information of the method.
       
    73 */
       
    74 #define LOG_ENTERFN( a ) write_log (EEnterFunction, a)
       
    75 /**
       
    76 * Use this function right before you leave the method.
       
    77 * @param a Leaving information of the method.
       
    78 */
       
    79 #define LOG_LEAVEFN( a ) write_log (ELeaveFunction, a)
       
    80 
       
    81 /**
       
    82 * Use this function at any points of a function for logging the current state.
       
    83 * @param a String to be written into logfile about the current state
       
    84 */
       
    85 #define LOG_WRITE( a ) write_log (EWriteLog, a)
       
    86 /**
       
    87 * Use this function at any points of a function for logging the current state.
       
    88 * You can use printf-like formats, but with only one parameter to be substituted..
       
    89 * @param a Format string,
       
    90 * @param b Parameter to be substituted.
       
    91 */
       
    92 #define LOG_WRITE_FORMAT( a, b ) write_log (EWriteLog, a, b)
       
    93 
       
    94 inline void write_log (TInt aSelector, const char* aFmt,...) //lint !e960
       
    95     {
       
    96     TBuf8<256> buf;
       
    97         {
       
    98 	    VA_LIST ap;//lint !e960
       
    99         TPtrC8 fmt((unsigned char *)aFmt);
       
   100 	    VA_START(ap, aFmt);  //lint !e960
       
   101 	    buf.FormatList(fmt, ap);
       
   102 	    VA_END(ap);  //lint !e960
       
   103         }
       
   104     switch(aSelector)
       
   105         {
       
   106         case EEnterFunction:
       
   107             buf.Insert(0, KLogEnterFn);
       
   108             break;
       
   109         case ELeaveFunction:
       
   110             buf.Insert(0, KLogLeaveFn);
       
   111             break;
       
   112         default:
       
   113             break;
       
   114         }
       
   115 
       
   116     RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, buf);
       
   117 
       
   118     TBuf<256> tempBuf;
       
   119     tempBuf.Copy( buf );
       
   120     RDebug::Print( tempBuf );
       
   121     }
       
   122 
       
   123 #define LOG_HEXDUMP(aBuf) { \
       
   124     RFileLogger::HexDump(KLogDir, KLogFile, EFileLoggingModeAppend, \
       
   125     ((const TText *)" "), ((const TText *)" "), aBuf.Ptr(), aBuf.Size());}
       
   126 
       
   127 
       
   128 #else // _DEBUG || _SECMODUI_LOG_
       
   129 
       
   130 // Empty macros
       
   131 #define LOG_CREATE 
       
   132 #define LOG_DELETE
       
   133 #define LOG_ENTERFN( a )
       
   134 #define LOG_LEAVEFN( a )
       
   135 #define LOG_WRITE( a )
       
   136 #define LOG_WRITE_FORMAT( a, b )
       
   137 #define LOG_HEXDUMP( a)
       
   138 
       
   139 #endif // _DEBUG || _SECMODUI_LOG_
       
   140 
       
   141 #endif	// SECMODUI_LOGGER_H
       
   142 
       
   143 // End of file