1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 19 /*! \file pvlogger.h 20 \brief This file contains basic logger interfaces for common use across platforms. 21 22 This is the main entry point header file for the logger library. It should be 23 the only one users directly include. 24 */ 25 26 #ifndef PVLOGGER_H_INCLUDED 27 #define PVLOGGER_H_INCLUDED 28 29 #ifndef OSCL_BASE_H_INCLUDED 30 #include "oscl_base.h" 31 #endif 32 33 #ifndef OSCL_VECTOR_H_INCLUDED 34 #include "oscl_vector.h" 35 #endif 36 37 #ifndef OSCL_DEFALLOC_H_INCLUDED 38 #include "oscl_defalloc.h" 39 #endif 40 41 #ifndef OSCL_SHARED_PTR_H 42 #include "oscl_shared_ptr.h" 43 #endif 44 45 #ifndef OSCL_BASE_ALLOC_H_INCLUDED 46 #include "oscl_base_alloc.h" 47 #endif 48 49 50 const int32 PVLOGGER_LEVEL_UNINTIALIZED = -1; 51 52 53 54 //////////////////////////////////////////// 55 // The instrumentation layer allows groups 56 // of messages to be compiled in or out of 57 // the code based on a build-time parameter. 58 ///////////////////////////////////////////// 59 60 /** 61 * Release Layer 62 * 63 * The release layer should only be used for messages that 64 * should remain in the final release. In certain cases all 65 * messaging may be disabled depending on customer requirements. 66 * However, when allowed the release layer should contain 67 * information that will be useful diagnosing problems in a 68 * released product (perhaps after entering a diagnostic mode), 69 * but with absolutely minimal performance impact when disabled 70 * at runtime. 71 */ 72 #define PVLOGMSG_INST_REL 0 73 /** 74 * Profile Layer 75 * 76 * The profile layer is used for messages and information 77 * related to messuring and reporting performance-related 78 * information. 79 */ 80 #define PVLOGMSG_INST_PROF 1 81 /** 82 * High Level Debug Layer 83 * 84 * This layer should contain messages that have very minimal 85 * impact on performance, but are at lower level (i.e., provide 86 * more information) than would be appropriate in a shipping 87 * product. The messages are probably used to gather information 88 * and validate proper functionality at a high level as might 89 * be appropriate for IOT, stress testing, or QA testing. 90 */ 91 #define PVLOGMSG_INST_HLDBG 2 92 /** 93 * Mid Level Debug Layer 94 * 95 * This layer should contain messages that are useful in the 96 * middle stages of the development cycle where major components 97 * are being integrated. The components themselves should 98 * already be well-tested so the emphasis is on interfaces 99 * between these components and integration testing. Messages 100 * at this layer may have some performance impact. 101 */ 102 #define PVLOGMSG_INST_MLDBG 3 103 /** 104 * Low Level Debug Layer 105 * 106 * This layer should contain messages for early functional 107 * testing. The messages are typically at a very low-level 108 * and allow testing the functionality of individual modules 109 * and components. Messages at this layer will typically have 110 * a performance impact (sometimes significant) due to the 111 * fact that they are at such a low level. 112 */ 113 #define PVLOGMSG_INST_LLDBG 4 114 115 /* 116 ** Default logger instrumentation level. To override this 117 ** setting, define PVLOGGER_INST_LEVEL in the osclconfig.h file. 118 ** Possible values and the resulting intrumentation: 119 ** 120 ** PVLOGGER_INST_LEVEL 0 : No logging. All logging statements compiled out. 121 ** PVLOGGER_INST_LEVEL 1 : Release level only. 122 ** PVLOGGER_INST_LEVEL 2 : Release level + profile level 123 ** PVLOGGER_INST_LEVEL 3 : Release level + profile level + high-level debug 124 ** PVLOGGER_INST_LEVEL 4 : Release level + profile level + high-level debug + mid-level debug 125 ** PVLOGGER_INST_LEVEL 5 & above : Release level + profile level + high-level debug 126 ** + mid-level debug + low-level debug 127 */ 128 #ifndef PVLOGGER_INST_LEVEL 129 #if defined(NDEBUG) 130 /* Release mode-- No logging */ 131 #define PVLOGGER_INST_LEVEL 0 132 #else 133 /* Debug mode-- Complete logging */ 134 #define PVLOGGER_INST_LEVEL 5 135 #endif 136 #endif 137 138 139 #if (PVLOGGER_INST_LEVEL<1) 140 141 /* 142 ** Disable and compile-out all logging 143 */ 144 #define PVLOGGER_LOGMSG(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 145 #define PVLOGGER_LOGMSG_V(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 146 #define PVLOGGER_LOGBIN(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 147 #define PVLOGGER_LOGBIN_V(IL, LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 148 #define PVLOGGER_LOG_USE_ONLY(x) 149 150 #else //PVLOGGER_INST_LEVEL 151 152 /* 153 ** Internal use macros that make the logging calls to PVLogger. 154 */ 155 #define _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE)\ 156 {\ 157 if (LOGGER)\ 158 {\ 159 if (LOGGER->IsActive(LEVEL))\ 160 {\ 161 LOGGER->LogMsgString MESSAGE;\ 162 }\ 163 }\ 164 } 165 166 #define _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE)\ 167 {\ 168 if (LOGGER)\ 169 {\ 170 if (LOGGER->IsActive(LEVEL))\ 171 {\ 172 LOGGER->LogMsgStringV MESSAGE;\ 173 }\ 174 }\ 175 } 176 177 #define _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) \ 178 {\ 179 if (LOGGER)\ 180 {\ 181 if (LOGGER->IsActive(LEVEL))\ 182 {\ 183 LOGGER->LogMsgBuffers MESSAGE;\ 184 }\ 185 }\ 186 } 187 188 #define _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) \ 189 {\ 190 if (LOGGER)\ 191 {\ 192 if (LOGGER->IsActive(LEVEL))\ 193 {\ 194 LOGGER->LogMsgBuffersV MESSAGE;\ 195 }\ 196 }\ 197 } 198 199 /* 200 ** In case some compilers cannot support the instrumentation-level macros, 201 ** they can be disabled by defining PVLOGGER_INST_LEVEL_SUPPORT to 0 202 ** in their osclconfig.h. If instrumentation level is not supported, then 203 ** all instrumentation levels will be compiled in. 204 ** 205 ** If PVLOGGER_INST_LEVEL_SUPPORT is not defined, the default is set here to allow 206 ** compile-time instrumentation level support. 207 */ 208 #ifndef PVLOGGER_INST_LEVEL_SUPPORT 209 #define PVLOGGER_INST_LEVEL_SUPPORT 1 210 #endif 211 212 #if !(PVLOGGER_INST_LEVEL_SUPPORT) 213 214 /* 215 ** A set of logging macros that ignore the instrumentation level. 216 ** All instrumentation levels will be compiled in. 217 */ 218 #define PVLOGGER_LOGMSG(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE) 219 #define PVLOGGER_LOGMSG_V(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE) 220 #define PVLOGGER_LOGBIN(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) 221 #define PVLOGGER_LOGBIN_V(IL, LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) 222 223 #else //PVLOGGER_INST_LEVEL_SUPPORT 224 225 /* 226 ** This set of macros compiles the logging statements in or out based on the instrumtation 227 ** level. 228 */ 229 230 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_REL) 231 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE) 232 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE) 233 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) 234 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) 235 #else 236 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 237 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 238 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 239 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_REL(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 240 #endif 241 242 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_PROF) 243 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE) 244 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE) 245 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) 246 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) 247 #else 248 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 249 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 250 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 251 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_PROF(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 252 #endif 253 254 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_HLDBG) 255 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE) 256 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE) 257 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) 258 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) 259 #else 260 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 261 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 262 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 263 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_HLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 264 #endif 265 266 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_MLDBG) 267 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE) 268 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE) 269 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) 270 #define PVLOGGER_LOGBIN_V_PVLOGMSG_V_INST_MLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) 271 #else 272 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 273 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 274 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 275 #define PVLOGGER_LOGBIN_V_PVLOGMSG_V_INST_MLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 276 #endif 277 278 #if (PVLOGGER_INST_LEVEL > PVLOGMSG_INST_LLDBG) 279 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG(LOGGER, LEVEL, MESSAGE) 280 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGMSG_V(LOGGER, LEVEL, MESSAGE) 281 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN(LOGGER, LEVEL, MESSAGE) 282 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) _PVLOGGER_LOGBIN_V(LOGGER, LEVEL, MESSAGE) 283 #else 284 #define PVLOGGER_LOGMSG_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 285 #define PVLOGGER_LOGMSG_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 286 #define PVLOGGER_LOGBIN_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 287 #define PVLOGGER_LOGBIN_V_PVLOGMSG_INST_LLDBG(LOGGER, LEVEL, MESSAGE) OSCL_UNUSED_ARG(LOGGER); 288 #endif 289 290 291 /** 292 * This is the text based API to log messages 293 * 294 * @param IL Instrumentation level. 295 * @param LOGGER Pointer to the logger object, that acts as the logging 296 * control/interface point 297 * @param LEVEL Log level of the message 298 * @param MESSAGE Log Message which includes the message id, and any kind 299 * of formatting information 300 * 301 * Example Usage: 302 * PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, logger_1, PVLOGMSG_WARNING, (13, "Test Messsage to Node 1\n")); 303 * -This message of log level PVLOGMSG_WARNING, and has a message id of 13 304 */ 305 #define PVLOGGER_LOGMSG(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGMSG_ ## IL (LOGGER, LEVEL, MESSAGE) 306 #define PVLOGGER_LOGMSG_V(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGMSG_V_ ## IL (LOGGER, LEVEL, MESSAGE) 307 308 /** 309 * This is a binary API to log messages 310 * 311 * @param IL Instrumentation level. 312 * @param LOGGER Pointer to the logger object, that acts as the logging 313 * control/interface point 314 * @param LEVEL Log level of the message 315 * @param MESSAGE Log Message which includes the message id, and message 316 * buffers that need to be logged. 317 * 318 * Example Usage: 319 * PVLOGGER_LOGBIN (PVLOGMSG_INST_LLDBG, logger_1, PVLOGMSG_WARNING, (10, 3, msgBuf1Size, msgBuf1, 320 * msgBuf2Size, msgBuf2, 321 * msgBuf3Size, msgBuf3)); 322 * 323 * -This message contains THREE (ptr_len, ptr) pairs. 324 * Log level of this msg is PVLOGMSG_WARNING, 325 * message id is 10. 326 */ 327 #define PVLOGGER_LOGBIN(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGBIN_ ## IL (LOGGER, LEVEL, MESSAGE) 328 #define PVLOGGER_LOGBIN_V(IL, LOGGER, LEVEL, MESSAGE) PVLOGGER_LOGBIN_V_ ## IL (LOGGER, LEVEL, MESSAGE) 329 330 #endif //PVLOGGER_INST_LEVEL_SUPPORT 331 332 /** 333 * Used to compile in/out lines of code that are used only 334 * for PVLogger macros. 335 * 336 * This code will be removed at compile time when PVLogger 337 * is disabled, i.e. Release mode. So do not put in any 338 * code that is necessary for correct functionality of the module 339 */ 340 #define PVLOGGER_LOG_USE_ONLY(x) x 341 342 #endif // PVLOGGER_INST_LEVEL 343 344 /** 345 * In case logging is compiled out, there is no need to compile 346 * the logger runtime code either. 347 */ 348 #ifndef PVLOGGER_ENABLE 349 #if (PVLOGGER_INST_LEVEL<1) 350 #define PVLOGGER_ENABLE 0 351 #else 352 #define PVLOGGER_ENABLE 1 353 #endif 354 #endif 355 356 /** 357 * Class: PVLogger 358 * 359 * Each logger instance is associated with a unique tag. PVLoggerRegistry 360 * class, maintains a repository of all the loggers, along with their 361 * associated tags. Each logger has an associated list of appenders. Appenders 362 * are entities that act as a sink for all the incoming messages. They could be 363 * file appenders, serial port appenders, buffer appenders etc. Each logger 364 * also has a list of message filters. These filters remove any unwanted messages 365 * from the output. 366 */ 367 class PVLoggerAppender; 368 class PVLoggerFilter; 369 class PVLogger 370 { 371 public: 372 373 typedef int32 log_level_type; 374 typedef int32 message_id_type; 375 typedef int32 filter_status_type; 376 typedef _OsclBasicAllocator alloc_type; 377 378 /** 379 * PVLogger needs to be initialized once per thread. This 380 * creates the PVLogger singleton that is used throughout 381 * the duration of the thread. Initialization must occur 382 * before the first message is logged. 383 * 384 * @exception leaves if out of memory 385 */ 386 OSCL_IMPORT_REF static void Init(); 387 388 389 /** 390 * Frees the PVLogger singleton used by the current thread. 391 * This must be called before thread exit. No messages 392 * can be logged after cleanup. 393 * 394 * @return 395 */ 396 OSCL_IMPORT_REF static void Cleanup(); 397 398 /** 399 * This is a factory method to create a log control point, with a 400 * certain input tag. There is a central registry of all the loggers, 401 * with their corresponding tags, called PV Logger Registry. In case 402 * the logger with the specified tag exists in the global registry, it 403 * is returned, else a new one is created and a pointer to the same is 404 * returend. 405 * 406 * @param inputTag logger tag, viz. "x.y.z" 407 * @param level log level associated with the logging control point 408 * (All messages with log levels less than equal to the 409 * log level of the control point would be logged) 410 * 411 * @param oAppenderInheritance 412 * 413 * @return PVLogger* Pointer to the logging control point 414 * 415 * @exception leaves if out of memory 416 */ 417 418 OSCL_IMPORT_REF static PVLogger *GetLoggerObject(const char* inputTag); 419 420 /** 421 * This method is used to set the log level of a control point. 422 * 423 * @param level log level associated with the logging control point 424 * 425 * @return NONE 426 */ SetLogLevel(log_level_type level)427 void SetLogLevel(log_level_type level) 428 { 429 #if(PVLOGGER_ENABLE) 430 _level = level; 431 #else 432 OSCL_UNUSED_ARG(level); 433 #endif 434 } 435 436 /** 437 * This method is used to set the log level of a control point, as well as 438 * to propagate the level to all the descendants of this control point. 439 * 440 * @param level log level associated with the logging control point 441 * 442 * @return NONE 443 */ 444 OSCL_IMPORT_REF void SetLogLevelAndPropagate(log_level_type level); 445 446 /** 447 * This method returns the log level of a control point. This could either 448 * have been set explicitly by the user (at the time of creation or later) 449 * or could have been inherited from one of its ancestors. 450 * 451 * @return log level associated with the logging control point 452 */ GetLogLevel()453 log_level_type GetLogLevel() 454 { 455 #if(PVLOGGER_ENABLE) 456 return(_level); 457 #else 458 return 0; 459 #endif 460 } 461 462 /** 463 * This method disables appender inheritance for the logging control point 464 * 465 */ DisableAppenderInheritance()466 void DisableAppenderInheritance() 467 { 468 #if(PVLOGGER_ENABLE) 469 _oAppenderInheritance = false; 470 #endif 471 } 472 473 /** 474 * This method adds an appender to the logging control point. Each logger 475 * maintains a list of appenders. Any msg to a logger if deemed active is 476 * logged to all the appenders. 477 * 478 * @param appender pointer to the appender to add 479 * 480 * @return NONE 481 * 482 * @exception leaves if out of memory 483 */ AddAppender(OsclSharedPtr<PVLoggerAppender> & appender)484 void AddAppender(OsclSharedPtr<PVLoggerAppender> &appender) 485 { 486 #if(PVLOGGER_ENABLE) 487 _pOwnAppenderVec.push_back(appender); 488 #else 489 OSCL_UNUSED_ARG(appender); 490 #endif 491 } 492 493 /** 494 * This method removes an appender from the logging control point. Each logger 495 * maintains a list of appenders. Any msg to a logger if deemed active is 496 * logged to all the appenders. 497 * 498 * @param appender pointer to the appender to delete 499 * 500 * @return NONE 501 */ RemoveAppender(OsclSharedPtr<PVLoggerAppender> & appender)502 void RemoveAppender(OsclSharedPtr<PVLoggerAppender> &appender) 503 { 504 #if(PVLOGGER_ENABLE) 505 for (Oscl_Vector<OsclSharedPtr<PVLoggerAppender>, alloc_type>::iterator it = _pOwnAppenderVec.begin(); 506 it != _pOwnAppenderVec.end(); 507 it++) 508 { 509 if ((*it).GetRep() == appender.GetRep()) 510 { 511 _pOwnAppenderVec.erase(it); 512 break; 513 } 514 } 515 #else 516 OSCL_UNUSED_ARG(appender); 517 #endif 518 } 519 520 /** 521 * This method adds a message filter to the logging control point. Each logger 522 * maintains a list of filters. Any msg to a logger if deemed active is 523 * passed through the msg filters prior to logging. 524 * 525 * @param msgFilter pointer to the filter to add 526 * 527 * @return NONE 528 * 529 * @exception leaves if out of memory 530 */ AddFilter(OsclSharedPtr<PVLoggerFilter> & filter)531 void AddFilter(OsclSharedPtr<PVLoggerFilter> &filter) 532 { 533 #if(PVLOGGER_ENABLE) 534 _pMsgFilterVec.push_back(filter); 535 #else 536 OSCL_UNUSED_ARG(filter); 537 #endif 538 }; 539 540 /** 541 * This method returns the number of appenders attached to the logging control point. 542 */ GetNumAppenders()543 uint32 GetNumAppenders() 544 { 545 #if(PVLOGGER_ENABLE) 546 return(_pOwnAppenderVec.size()); 547 #else 548 return 0; 549 #endif 550 } 551 552 /** 553 * This method determines if a msg passed to the logging control point is active 554 * or not. Only messages that are deemed active are logged. Messages are considered 555 * not active if any of the following criteria are met: 556 * - All logging is disabled at this logging control point 557 * - If all the log levels, leading upto the root log point are uninitialized 558 * - If the log level of the incoming message is LESS THAN that of the active 559 * log level of the logging control point. 560 * 561 * @return BOOL 562 */ 563 OSCL_IMPORT_REF bool IsActive(log_level_type level); 564 565 /** 566 * This method logs formatted text msg to all the appenders, after running thrrough 567 * the message filters. After logging the message to the appenders attached to the 568 * current control point, the message is passed up to the parent node, only if 569 * appender inheritance is enabled. 570 * 571 * 572 * @param msgID Message ID, that is unique to a message 573 * @param fmt format string, similar to one taken by printf 574 * @param arguments Variable list of arguments 575 * 576 * @return NONE 577 */ 578 OSCL_IMPORT_REF void LogMsgStringV(message_id_type msgID, const char * fmt, va_list arguments); 579 580 /** 581 * This method logs opaque data buffers to all the appenders, after running thrrough 582 * the message filters. After logging the message to the appenders attached to the 583 * current control point, the message is passed up to the parent node, only if 584 * appender inheritance is enabled. 585 * 586 * 587 * @param msgID Message ID, that is unique to a message 588 * @param numPairs Number of (ptr_len, ptr) pairs 589 * @param arguments Variable list of arguments 590 * 591 * @return NONE 592 */ 593 OSCL_IMPORT_REF void LogMsgBuffersV(message_id_type msgID, int32 numPairs, va_list arguments); 594 595 /** 596 * This method logs formatted text msg to all the appenders, after running thrrough 597 * the message filters. After logging the message to the appenders attached to the 598 * current control point, the message is passed up to the parent node, only if 599 * appender inheritance is enabled. 600 * 601 * 602 * @param msgID Message ID, that is unique to a message 603 * @param fmt format string, similar to one taken by printf 604 * @param arguments Variable list of arguments 605 * 606 * @return NONE 607 */ 608 OSCL_IMPORT_REF void LogMsgString(message_id_type msgID, const char * fmt, ...); 609 610 /** 611 * This method logs opaque data buffers to all the appenders, after running thrrough 612 * the message filters. After logging the message to the appenders attached to the 613 * current control point, the message is passed up to the parent node, only if 614 * appender inheritance is enabled. 615 * 616 * 617 * @param msgID Message ID, that is unique to a message 618 * @param numPairs Number of (ptr_len, ptr) pairs 619 * @param arguments Variable list of arguments 620 * 621 * @return NONE 622 */ 623 OSCL_IMPORT_REF void LogMsgBuffers(message_id_type msgID, int32 numPairs, ...); 624 625 /** 626 * Logger Constructor 627 * 628 * 629 * @param tag Logger tag, unique to a logging control point 630 * @param level Active Log level of the logger 631 * @param oAppenderInheritance 632 * 633 * @return NONE 634 */ 635 OSCL_IMPORT_REF PVLogger(const char* inputTag, log_level_type level, bool oAppenderInheritance); 636 ~PVLogger()637 virtual ~PVLogger() 638 { 639 #if(PVLOGGER_ENABLE) 640 _tagAllocator.deallocate(_tag); 641 #endif 642 } 643 644 #if(PVLOGGER_ENABLE) 645 protected: 646 friend class PVLoggerRegistry; SetParent(PVLogger * parentLogger)647 void SetParent(PVLogger *parentLogger) 648 { 649 _parentLogger = parentLogger; 650 } GetParent()651 PVLogger *GetParent() 652 { 653 return(_parentLogger); 654 } 655 656 private: 657 filter_status_type FilterMsg(message_id_type msgID); 658 void LogMsg(message_id_type msgID, const char *fmt, va_list arguments); 659 void LogMsg(message_id_type msgID, int32 numPairs, va_list arguments); 660 661 char* _tag; 662 log_level_type _level; 663 log_level_type _lastMsgLevel; 664 bool _oAppenderInheritance; 665 666 PVLogger *_parentLogger; 667 Oscl_TAlloc<char, alloc_type> _tagAllocator; 668 669 Oscl_Vector<OsclSharedPtr<PVLoggerFilter>, alloc_type> _pMsgFilterVec; 670 Oscl_Vector<OsclSharedPtr<PVLoggerAppender>, alloc_type> _pOwnAppenderVec; 671 #endif //PVLOGGER_ENABLE 672 }; 673 674 ////////////////////////////////////// 675 // log message levels 676 ////////////////////////////////////// 677 678 /** 679 * system is unusable 680 */ 681 const PVLogger::log_level_type PVLOGMSG_EMERG = 0; 682 /** 683 * action must be taken immediately 684 */ 685 const PVLogger::log_level_type PVLOGMSG_ALERT = 1; 686 /** 687 * critical conditions 688 */ 689 const PVLogger::log_level_type PVLOGMSG_CRIT = 2; 690 /** 691 * error conditions 692 */ 693 const PVLogger::log_level_type PVLOGMSG_ERR = 3; 694 /** 695 * warning conditions 696 */ 697 const PVLogger::log_level_type PVLOGMSG_WARNING = 4; 698 /** 699 * normal but significant condition 700 */ 701 const PVLogger::log_level_type PVLOGMSG_NOTICE = 5; 702 /** 703 * informational 704 */ 705 const PVLogger::log_level_type PVLOGMSG_INFO = 6; 706 /** 707 * function enter and exit 708 */ 709 const PVLogger::log_level_type PVLOGMSG_STACK_TRACE = 7; 710 /** 711 * debug-level messages 712 */ 713 const PVLogger::log_level_type PVLOGMSG_DEBUG = 8; 714 715 /////////////////////////////////// 716 // do not use these levels 717 // for backward compatibility only 718 /////////////////////////////////// 719 const PVLogger::log_level_type PVLOGMSG_FATAL_ERROR = PVLOGMSG_EMERG; 720 const PVLogger::log_level_type PVLOGMSG_NONFATAL_ERROR = PVLOGMSG_ERR; 721 const PVLogger::log_level_type PVLOGMSG_STATISTIC = PVLOGMSG_INFO; 722 const PVLogger::log_level_type PVLOGMSG_VERBOSE = PVLOGMSG_DEBUG; 723 724 #endif // PVLOGGER_H_INCLUDED 725