metadataengine/server/inc/mdslogger.h
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  This class is for Server logging usage*
       
    15 */
       
    16 
       
    17 #ifndef __MDSLOGGER_H__
       
    18 #define __MDSLOGGER_H__
       
    19 
       
    20 #include <e32std.h>
       
    21 #include <e32base.h>
       
    22 #include <s32file.h>
       
    23 #include <charconv.h>
       
    24 #include <convgeneratedcpp.h>
       
    25 
       
    26 #include "flogger.h"
       
    27 #include "harvesterlog.h"
       
    28 
       
    29 class CMdsClauseBuffer;
       
    30 class RRowData;
       
    31 class TColumn;
       
    32 
       
    33 /**
       
    34 * Logging categories.
       
    35 * If adding new categories, remember to add:
       
    36 * - a new activation flag to MMP file
       
    37 * - activation flag recognition code to logger.cpp
       
    38 */
       
    39 enum TLogCategory
       
    40     {
       
    41     ELogAlways      = 0x0001, // logged always (if feature is on)
       
    42     ELogQuery       = 0x0002, // DB queries
       
    43     ELogDb          = 0x0004, // DB interface activity
       
    44     ELogMutex       = 0x0008, // mutex
       
    45     ELogServer      = 0x0010, // client/server commands
       
    46     };
       
    47 
       
    48 
       
    49 #ifdef LOG_MASTER_FLAG
       
    50 
       
    51 const TChar KNewLine = '\n';
       
    52 const TInt KLineLength = 80;
       
    53 const TInt KLineBuffer = 512;
       
    54 const TUint32 KLogfileMaxLength = 10240;
       
    55 
       
    56 _LIT(KDirectory, "Metadata");
       
    57 _LIT(KFilename, "server.txt");
       
    58 _LIT(KAltFilename, "server2.txt");
       
    59 
       
    60 #define MDE_FILE_LOGGING
       
    61 
       
    62 // CLASS DECLARATION
       
    63 /**
       
    64 * CMdSLogger.
       
    65 * Class created log for server.
       
    66 */
       
    67 class CMdSLogger : public CBase
       
    68     {
       
    69     public: // Constructors and destructor
       
    70 
       
    71 	    /**
       
    72 	    * Constructs a new logger implementation.
       
    73 	    *
       
    74 	    * @return  metadata logger implementation
       
    75 	    */
       
    76         static CMdSLogger* NewInstanceL();
       
    77 
       
    78         virtual ~CMdSLogger();
       
    79 
       
    80         /**
       
    81 	    * Writes text to logfile, active version
       
    82 	    */
       
    83         void LogLit( const TDesC8& aText );
       
    84 
       
    85         /**
       
    86 	    * Writes text to logfile, active version
       
    87 	    */
       
    88         void LogLit( const TDesC16& aText );
       
    89 
       
    90         /**
       
    91         * returns a reference to the file logger resource
       
    92         */
       
    93         inline RFileLogger& Log();
       
    94 
       
    95         /**
       
    96         * tests if a logging category is active
       
    97         */
       
    98         inline TBool IsActive( TLogCategory aCategory );
       
    99 
       
   100         /**
       
   101         * activates a certain logging category
       
   102         */
       
   103         inline void Activate( TLogCategory aCategory );
       
   104 
       
   105         /**
       
   106         * deactivates a certain logging category
       
   107         */
       
   108         inline void Deactivate( TLogCategory aCategory );
       
   109 
       
   110         /**
       
   111         * Checks if size exceeds maximum limit
       
   112         * @param aLines how many lines has been added since last update
       
   113         */
       
   114         void CheckSize( TInt aLines );
       
   115 
       
   116 		// used for logging
       
   117 		CMdsClauseBuffer* DescribeL( const CMdsClauseBuffer& aBuffer, const RRowData& aRowData );
       
   118 	
       
   119 		CMdsClauseBuffer* DescribeFullL( const TDesC& aBuffer, const RRowData& aRowData );
       
   120 	
       
   121 		void LogVariableL( CMdsClauseBuffer& aBuf, const TColumn& aColumn );
       
   122 
       
   123     private: // Private constructors
       
   124 
       
   125         /**
       
   126         * CMdSLogger.
       
   127         * C++ default constructor.
       
   128         */
       
   129         CMdSLogger();
       
   130 
       
   131         /**
       
   132         * ConstructL.
       
   133         * 2nd phase constructor.
       
   134         */
       
   135         void ConstructL();
       
   136 
       
   137     private:
       
   138 
       
   139         /** the file logger resource */
       
   140         RFileLogger iLog;
       
   141 
       
   142         /** counter for lines */
       
   143         TUint32 iLineCounter;
       
   144 
       
   145         /**
       
   146         * currently active logging categories (masked)
       
   147         */
       
   148         TUint32 iActiveCategories;
       
   149         
       
   150         TBool iAltFileFlag;
       
   151         
       
   152         TBool iValid;
       
   153     };
       
   154 
       
   155 #include "mdslogger.inl"
       
   156     
       
   157     #define __DEFINE_LOGGER             class CMdSLogger* gLogger;
       
   158     #define __USES_LOGGER               extern CMdSLogger* gLogger;
       
   159     #define __INIT_LOGGER               gLogger = CMdSLogger::NewInstanceL();
       
   160     #define __DESTROY_LOGGER            {if(gLogger){delete gLogger;gLogger=NULL;}}
       
   161 	#define __LOGLB(CATEGORY,A)         {if (gLogger->IsActive(CATEGORY)) { gLogger->LogLit( _L(A) ); }}
       
   162 	#define __LOG(CATEGORY,A)           {if (gLogger->IsActive(CATEGORY)) { gLogger->LogLit( A ); }}
       
   163 #ifdef MDE_FILE_LOGGING
       
   164     #define __LOG1(CATEGORY,A,B)        {if (gLogger->IsActive(CATEGORY)) { gLogger->Log().WriteFormat( _L(A), B ); gLogger->CheckSize( 1 ); }}
       
   165     #define __LOG2(CATEGORY,A,B,C)      {if (gLogger->IsActive(CATEGORY)) { gLogger->Log().WriteFormat( _L(A), B, C ); gLogger->CheckSize( 1 ); }}
       
   166     #define __LOG3(CATEGORY,A,B,C,D)    {if (gLogger->IsActive(CATEGORY)) { gLogger->Log().WriteFormat( _L(A), B, C, D ); gLogger->CheckSize( 1 ); }}
       
   167 #else
       
   168 	#define __LOG1(CATEGORY,A,B)        {if (gLogger->IsActive(CATEGORY)) { RDebug::Print( _L(A), B ); }}
       
   169 	#define __LOG2(CATEGORY,A,B,C)      {if (gLogger->IsActive(CATEGORY)) { RDebug::Print( _L(A), B, C ); }}
       
   170 	#define __LOG3(CATEGORY,A,B,C,D)    {if (gLogger->IsActive(CATEGORY)) { RDebug::Print( _L(A), B, C, D ); }}
       
   171 #endif
       
   172 
       
   173 	#ifdef LOG_QUERY
       
   174 	    #define __LOGQUERY_16(INFO, BUFFER, ROWDATA) \
       
   175 	    	{__LOG( ELogQuery, INFO); \
       
   176 	        CMdsClauseBuffer* queryText = gLogger->DescribeFullL(BUFFER,ROWDATA); \
       
   177 	        if ( queryText ) { __LOG( ELogQuery, queryText->ConstBufferL() ); \
       
   178 	        delete queryText;} }
       
   179 	#else //LOG_QUERY
       
   180 	    #define __LOGQUERY_16(INFO, BUFFER, ROWDATA)
       
   181 	#endif //LOG_QUERY
       
   182 
       
   183 #else
       
   184     #define __DEFINE_LOGGER 
       
   185     #define __USES_LOGGER
       
   186     #define __INIT_LOGGER
       
   187     #define __DESTROY_LOGGER
       
   188     #define __LOGLB(CATEGORY,A)
       
   189     #define __LOG(CATEGORY,A)
       
   190     #define __LOG1(CATEGORY,A,B)
       
   191     #define __LOG2(CATEGORY,A,B,C)
       
   192     #define __LOG3(CATEGORY,A,B,C,D)
       
   193 	#define __LOGQUERY_16(INFO, BUFFER, ROWDATA)
       
   194 #endif  // METADATA_LOG
       
   195 
       
   196 
       
   197 #endif  //__MDSLOGGER_H__