Main Page Modules Class Hierarchy Data Structures File List Data Fields Globals Related Pages

# pvlogger.h

Go to the documentation of this file.

    00001
    00009 #ifndef PVLOGGER_H_INCLUDED
    00010 #define PVLOGGER_H_INCLUDED
    00011
    00012 #ifndef OSCL_BASE_H_INCLUDED
    00013 #include "oscl_base.h"
    00014 #endif
    00015
    00016 #ifndef OSCL_VECTOR_H_INCLUDED
    00017 #include "oscl_vector.h"
    00018 #endif
    00019
    00020 #ifndef OSCL_DEFALLOC_H_INCLUDED
    00021 #include "oscl_defalloc.h"
    00022 #endif
    00023
    00024 #ifndef OSCL_SHARED_PTR_H
    00025 #include "oscl_shared_ptr.h"
    00026 #endif
    00027
    00028 #ifndef OSCL_BASE_ALLOC_H_INCLUDED
    00029 #include "oscl_base_alloc.h"
    00030 #endif
    00031
    00032
    00033 const int32 PVLOGGER_LEVEL_UNINTIALIZED = -1;
    00034
    00035
    00036
    00038 // The instrumentation layer allows groups
    00039 // of messages to be compiled in or out of
    00040 // the code based on a build-time parameter.
    00042
    00055 #define PVLOGMSG_INST_REL   0
    00056
    00063 #define PVLOGMSG_INST_PROF  1
    00064
    00074 #define PVLOGMSG_INST_HLDBG 2
    00075
    00085 #define PVLOGMSG_INST_MLDBG 3
    00086
    00096 #define PVLOGMSG_INST_LLDBG 4
    00097
    00098 /*
    00099 ** Default logger instrumentation level.  To override this
    00100 ** setting, define PVLOGGER_INST_LEVEL in the osclconfig.h file.
    00101 ** Possible values and the resulting intrumentation:
    00102 **
    00103 **  PVLOGGER_INST_LEVEL 0 : No logging.  All logging statements compiled out.
    00104 **  PVLOGGER_INST_LEVEL 1 : Release level only.
    00105 **  PVLOGGER_INST_LEVEL 2 : Release level + profile level
    00106 **  PVLOGGER_INST_LEVEL 3 : Release level + profile level + high-level debug
    00107 **  PVLOGGER_INST_LEVEL 4 : Release level + profile level + high-level debug + mid-level debug
    00108 **  PVLOGGER_INST_LEVEL 5 & above : Release level + profile level + high-level debug
    00109 **                            + mid-level debug + low-level debug
    00110 */
    00111 #ifndef PVLOGGER_INST_LEVEL
    00112 #if (OSCL_RELEASE_BUILD)
    00113 /* Release mode-- Profile logging */
    00114 #define PVLOGGER_INST_LEVEL 2
    00115 #else
    00116 /* Debug mode-- Complete logging */
    00117 #define PVLOGGER_INST_LEVEL 5
    00118 #endif
    00119 #endif
    00120
    00121
    00122 #if (PVLOGGER_INST_LEVEL<1)
    00123
    00124 /*
    00125 ** Disable and compile-out all logging
    00126 */
    00127 #define PVLOGGER_LOGMSG(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00128 #define PVLOGGER_LOGMSG_V(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00129 #define PVLOGGER_LOGBIN(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00130 #define PVLOGGER_LOGBIN_V(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00131 #define PVLOGGER_LOG_USE_ONLY(x)
    00132
    00133 #else //PVLOGGER_INST_LEVEL
    00134
    00135 /*
    00136 ** Internal use macros that make the logging calls to PVLogger.
    00137 */
    00138 #define _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)\
    00139 {\
    00140     if (LOGGER)\
    00141     {\
    00142         if (LOGGER->IsActive(LEVEL))\
    00143         {\
    00144             LOGGER->LogMsgString MESSAGE;\
    00145         }\
    00146     }\
    00147 }
    00148
    00149 #define _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)\
    00150 {\
    00151     if (LOGGER)\
    00152     {\
    00153         if (LOGGER->IsActive(LEVEL))\
    00154         {\
    00155             LOGGER->LogMsgStringV MESSAGE;\
    00156         }\
    00157     }\
    00158 }
    00159
    00160 #define _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) \
    00161 {\
    00162     if (LOGGER)\
    00163     {\
    00164         if (LOGGER->IsActive(LEVEL))\
    00165         {\
    00166             LOGGER->LogMsgBuffers MESSAGE;\
    00167         }\
    00168     }\
    00169 }
    00170
    00171 #define _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) \
    00172 {\
    00173     if (LOGGER)\
    00174     {\
    00175         if (LOGGER->IsActive(LEVEL))\
    00176         {\
    00177             LOGGER->LogMsgBuffersV MESSAGE;\
    00178         }\
    00179     }\
    00180 }
    00181
    00182 /*
    00183 ** In case some compilers cannot support the instrumentation-level macros,
    00184 ** they can be disabled by defining PVLOGGER_INST_LEVEL_SUPPORT to 0
    00185 ** in their osclconfig.h.  If instrumentation level is not supported, then
    00186 ** all instrumentation levels will be compiled in.
    00187 **
    00188 ** If PVLOGGER_INST_LEVEL_SUPPORT is not defined, the default is set here to allow
    00189 ** compile-time instrumentation level support.
    00190 */
    00191 #ifndef PVLOGGER_INST_LEVEL_SUPPORT
    00192 #define PVLOGGER_INST_LEVEL_SUPPORT 1
    00193 #endif
    00194
    00195 #if !(PVLOGGER_INST_LEVEL_SUPPORT)
    00196
    00197 /*
    00198 ** A set of logging macros that ignore the instrumentation level.
    00199 ** All instrumentation levels will be compiled in.
    00200 */
    00201 #define PVLOGGER_LOGMSG(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)
    00202 #define PVLOGGER_LOGMSG_V(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)
    00203 #define PVLOGGER_LOGBIN(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE)
    00204 #define PVLOGGER_LOGBIN_V(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE)
    00205
    00206 #else //PVLOGGER_INST_LEVEL_SUPPORT
    00207
    00208 /*
    00209 ** This set of macros compiles the logging statements in or out based on the instrumtation
    00210 ** level.
    00211 */
    00212
    00213 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_REL)
    00214 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)
    00215 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)
    00216 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE)
    00217 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE)
    00218 #else
    00219 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00220 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00221 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00222 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00223 #endif
    00224
    00225 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_PROF)
    00226 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)
    00227 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)
    00228 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE)
    00229 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE)
    00230 #else
    00231 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00232 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00233 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00234 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00235 #endif
    00236
    00237 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_HLDBG)
    00238 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)
    00239 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)
    00240 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE)
    00241 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE)
    00242 #else
    00243 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00244 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00245 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00246 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00247 #endif
    00248
    00249 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_MLDBG)
    00250 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)
    00251 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)
    00252 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE)
    00253 #define PVLOGGER_LOGBIN_V_PVLOGMSG_V_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE)
    00254 #else
    00255 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00256 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00257 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00258 #define PVLOGGER_LOGBIN_V_PVLOGMSG_V_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00259 #endif
    00260
    00261 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_LLDBG)
    00262 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)
    00263 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)
    00264 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE)
    00265 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE)
    00266 #else
    00267 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00268 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00269 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00270 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER);
    00271 #endif
    00272
    00273
    00288 #define PVLOGGER_LOGMSG(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGMSG_ ## IL (LOGGER, LEVEL, MESSAGE)
    00289 #define PVLOGGER_LOGMSG_V(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGMSG_V_ ## IL (LOGGER, LEVEL, MESSAGE)
    00290
    00310 #define PVLOGGER_LOGBIN(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGBIN_ ## IL (LOGGER, LEVEL, MESSAGE)
    00311 #define PVLOGGER_LOGBIN_V(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGBIN_V_ ## IL (LOGGER, LEVEL, MESSAGE)
    00312
    00313 #endif //PVLOGGER_INST_LEVEL_SUPPORT
    00314
    00323 #define PVLOGGER_LOG_USE_ONLY(x) x
    00324
    00325 #endif // PVLOGGER_INST_LEVEL
    00326
    00331 #ifndef PVLOGGER_ENABLE
    00332 #if (PVLOGGER_INST_LEVEL<1)
    00333 #define PVLOGGER_ENABLE 0
    00334 #else
    00335 #define PVLOGGER_ENABLE 1
    00336 #endif
    00337 #endif
    00338
    00350 class PVLoggerAppender;
    00351 class PVLoggerFilter;
    00352 class PVLogger
    00353 {
    00354     public:
    00355
    00356         typedef int32 log_level_type;
    00357         typedef int32 message_id_type;
    00358         typedef int32 filter_status_type;
    00359         typedef _OsclBasicAllocator alloc_type;
    00360
    00369         OSCL_IMPORT_REF static void Init();
    00370
    00371
    00379         OSCL_IMPORT_REF static void Cleanup();
    00380
    00401         OSCL_IMPORT_REF static PVLogger *GetLoggerObject(const char* inputTag);
    00402
    00410         void SetLogLevel(log_level_type level)
    00411         {
    00412 #if(PVLOGGER_ENABLE)
    00413             _level = level;
    00414 #else
    00415             OSCL_UNUSED_ARG(level);
    00416 #endif
    00417         }
    00418
    00427         OSCL_IMPORT_REF void SetLogLevelAndPropagate(log_level_type level);
    00428
    00436         log_level_type GetLogLevel()
    00437         {
    00438 #if(PVLOGGER_ENABLE)
    00439             return(_level);
    00440 #else
    00441             return 0;
    00442 #endif
    00443         }
    00444
    00449         void DisableAppenderInheritance()
    00450         {
    00451 #if(PVLOGGER_ENABLE)
    00452             _oAppenderInheritance = false;
    00453 #endif
    00454         }
    00455
    00467         void AddAppender(OsclSharedPtr<PVLoggerAppender> &appender)
    00468         {
    00469 #if(PVLOGGER_ENABLE)
    00470             _pOwnAppenderVec.push_back(appender);
    00471 #else
    00472             OSCL_UNUSED_ARG(appender);
    00473 #endif
    00474         }
    00475
    00485         void RemoveAppender(OsclSharedPtr<PVLoggerAppender> &appender)
    00486         {
    00487 #if(PVLOGGER_ENABLE)
    00488             for (Oscl_Vector<OsclSharedPtr<PVLoggerAppender>, alloc_type>::iterator it = _pOwnAppenderVec.begin();
    00489                     it != _pOwnAppenderVec.end();
    00490                     it++)
    00491             {
    00492                 if ((*it).GetRep() == appender.GetRep())
    00493                 {
    00494                     _pOwnAppenderVec.erase(it);
    00495                     break;
    00496                 }
    00497             }
    00498 #else
    00499             OSCL_UNUSED_ARG(appender);
    00500 #endif
    00501         }
    00502
    00514         void AddFilter(OsclSharedPtr<PVLoggerFilter> &filter)
    00515         {
    00516 #if(PVLOGGER_ENABLE)
    00517             _pMsgFilterVec.push_back(filter);
    00518 #else
    00519             OSCL_UNUSED_ARG(filter);
    00520 #endif
    00521         };
    00522
    00526         uint32 GetNumAppenders()
    00527         {
    00528 #if(PVLOGGER_ENABLE)
    00529             return(_pOwnAppenderVec.size());
    00530 #else
    00531             return 0;
    00532 #endif
    00533         }
    00534
    00546         OSCL_IMPORT_REF bool IsActive(log_level_type level);
    00547
    00561         OSCL_IMPORT_REF void LogMsgStringV(message_id_type msgID, const char * fmt, va_list arguments);
    00562
    00576         OSCL_IMPORT_REF void LogMsgBuffersV(message_id_type msgID, int32 numPairs, va_list arguments);
    00577
    00591         OSCL_IMPORT_REF void LogMsgString(message_id_type msgID, const char * fmt, ...);
    00592
    00606         OSCL_IMPORT_REF void LogMsgBuffers(message_id_type msgID, int32 numPairs, ...);
    00607
    00618         OSCL_IMPORT_REF PVLogger(const char* inputTag, log_level_type level, bool oAppenderInheritance);
    00619
    00620         virtual ~PVLogger()
    00621         {
    00622 #if(PVLOGGER_ENABLE)
    00623             _tagAllocator.deallocate(_tag);
    00624 #endif
    00625         }
    00626
    00627 #if(PVLOGGER_ENABLE)
    00628     protected:
    00629         friend class PVLoggerRegistry;
    00630         void SetParent(PVLogger *parentLogger)
    00631         {
    00632             _parentLogger = parentLogger;
    00633         }
    00634         PVLogger *GetParent()
    00635         {
    00636             return(_parentLogger);
    00637         }
    00638
    00639     private:
    00640         filter_status_type FilterMsg(message_id_type msgID);
    00641         void LogMsg(message_id_type msgID, const char *fmt, va_list arguments);
    00642         void LogMsg(message_id_type msgID, int32 numPairs, va_list arguments);
    00643
    00644         char* _tag;
    00645         log_level_type _level;
    00646         log_level_type _lastMsgLevel;
    00647         bool _oAppenderInheritance;
    00648
    00649         PVLogger *_parentLogger;
    00650         Oscl_TAlloc<char, alloc_type> _tagAllocator;
    00651
    00652         Oscl_Vector<OsclSharedPtr<PVLoggerFilter>, alloc_type> _pMsgFilterVec;
    00653         Oscl_Vector<OsclSharedPtr<PVLoggerAppender>, alloc_type>  _pOwnAppenderVec;
    00654 #endif //PVLOGGER_ENABLE
    00655 };
    00656
    00658 // log message levels
    00660
    00664 const PVLogger::log_level_type PVLOGMSG_EMERG   = 0;
    00668 const PVLogger::log_level_type PVLOGMSG_ALERT   = 1;
    00672 const PVLogger::log_level_type PVLOGMSG_CRIT    = 2;
    00676 const PVLogger::log_level_type PVLOGMSG_ERR     = 3;
    00680 const PVLogger::log_level_type PVLOGMSG_WARNING = 4;
    00684 const PVLogger::log_level_type PVLOGMSG_NOTICE  = 5;
    00688 const PVLogger::log_level_type PVLOGMSG_INFO    = 6;
    00692 const PVLogger::log_level_type PVLOGMSG_STACK_TRACE = 7;
    00696 const PVLogger::log_level_type PVLOGMSG_DEBUG   = 8;
    00697
    00699 // do not use these levels
    00700 // for backward compatibility only
    00702 const PVLogger::log_level_type PVLOGMSG_FATAL_ERROR    = PVLOGMSG_EMERG;
    00703 const PVLogger::log_level_type PVLOGMSG_NONFATAL_ERROR = PVLOGMSG_ERR;
    00704 const PVLogger::log_level_type PVLOGMSG_STATISTIC      = PVLOGMSG_INFO;
    00705 const PVLogger::log_level_type PVLOGMSG_VERBOSE        = PVLOGMSG_DEBUG;
    00706
    00707 #endif // PVLOGGER_H_INCLUDED