logger_level_impl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __LOGGER_LEVEL_IMPL_H
  15. #define __LOGGER_LEVEL_IMPL_H
  16. #include <log4cplus/logger.h>
  17. #include <log/logger_level.h>
  18. namespace isc {
  19. namespace log {
  20. /// \brief Implementation aspects of logging levels
  21. ///
  22. /// This extends the log4cplus level set to allow 100 debug levels.
  23. ///
  24. /// First some terminology, as the use of the term "level" gets confusing. The
  25. /// code and comments here use the term "level" in two contexts:
  26. ///
  27. /// Logging level: The category of messages to log. By default log4cplus
  28. /// defines the following logging levels: OFF_LOG_LEVEL, FATAL_LOG_LEVEL,
  29. /// ERROR_LOG_LEVEL, WARN_LOG_LEVEL, INFO_LOG_LEVEL, DEBUG_LOG_LEVEL,
  30. /// TRACE_LOG_LEVEL, ALL_LOG_LEVEL (which here will be abbreviated OFF, FATAL
  31. /// etc.). Within the context of BIND-10, OFF, TRACE and ALL are not used
  32. /// and the idea of DEBUG has been extended, as will be seen below. In
  33. /// BIND 10 terms, this is known as "severity"; the "logging level" usage will
  34. /// usually be used when talking about log4cplus aspects of the idea (as
  35. /// log4cplus uses that teminology).
  36. ///
  37. /// Debug level: This is a number that ranges from 0 to 99 and is used by the
  38. /// application to control the detail of debug output. A value of 0 gives the
  39. /// highest-level debug output; a value of 99 gives the most verbose and most
  40. /// detailed. Debug messages (or whatever debug level) are only ever output
  41. /// when the logging level is set to DEBUG. (Note that the numbers 0 and 99
  42. /// are not hard-coded - they are the constants MIN_DEBUG_LEVEL and
  43. /// MAX_DEBUG_LEVEL.)
  44. ///
  45. /// With log4cplus, the various logging levels have a numeric value associated
  46. /// with them, such that FATAL > ERROR > WARNING etc. This suggests that the
  47. /// idea of debug levels can be incorporated into the existing logging level
  48. /// scheme by assigning them appropriate numeric values, i.e.
  49. ///
  50. /// WARNING > INFO > DEBUG > DEBUG - 1 > DEBUG - 2 > ... > DEBUG - 99
  51. ///
  52. /// Setting a numeric level of DEBUG enables the basic messages; setting higher
  53. /// debug levels (corresponding to lower numeric logging levels) will enable
  54. /// progressively more messages. The lowest debug level (0) is chosen such that
  55. /// it corresponds to the default level of DEBUG.
  56. ///
  57. /// This class comprises nothing more than static methods to aid the conversion
  58. /// of logging levels between log4cplus and BIND 10, and to register those
  59. /// levels with log4cplus.
  60. class LoggerLevelImpl {
  61. public:
  62. /// \brief Convert BIND 10 level to log4cplus logging level
  63. ///
  64. /// Converts the BIND 10 severity level into a log4cplus logging level.
  65. /// If the severity is DEBUG, the current BIND 10 debug level is taken
  66. /// into account when doing the conversion.
  67. ///
  68. /// \param level BIND 10 severity and debug level
  69. ///
  70. /// \return Equivalent log4cplus logging level.
  71. static
  72. log4cplus::LogLevel convertFromBindLevel(const isc::log::Level& level);
  73. /// \brief Convert log4cplus logging level to BIND 10 logging level
  74. ///
  75. /// Converts the log4cplus log level into a BIND 10 severity level.
  76. /// The log4cplus log level may be non-standard in which case it is
  77. /// encoding a BIND 10 debug level as well.
  78. ///
  79. /// \param loglevel log4cplus log level
  80. ///
  81. /// \return Equivalent BIND 10 severity and debug level
  82. static
  83. isc::log::Level convertToBindLevel(const log4cplus::LogLevel loglevel);
  84. /// \brief Convert string to log4cplus logging level
  85. ///
  86. /// BIND 10 extends the set of logging levels in log4cplus with a group
  87. /// of debug levels. These are given names DEBUG0 through DEBUG99 (with
  88. /// DEBUG0 being equivalent to DEBUG, the standard log level. If the name
  89. /// is DEBUGn but n lies outside the range of debug levels, debug level
  90. /// specifies is coerced to the nearest valid value. If the string is just
  91. /// not recognised, a NOT_SET_LOG_LEVEL is returned.
  92. ///
  93. /// \param level String representing the logging level.
  94. ///
  95. /// \return Corresponding log4cplus log level
  96. static
  97. log4cplus::LogLevel logLevelFromString(const log4cplus::tstring& level);
  98. /// \brief Convert log level to string
  99. ///
  100. /// If the log level is one of the extended debug levels, the string DEBUG
  101. /// is returned, otherwise the empty string.
  102. ///
  103. /// \param level Extended logging level
  104. ///
  105. /// \return Equivalent string.
  106. static log4cplus::tstring logLevelToString(log4cplus::LogLevel level);
  107. /// \brief Initialize extended logging levels
  108. ///
  109. /// This must be called once, after log4cplus has been initialized. It
  110. /// registers the level/string converter functions.
  111. static void init();
  112. };
  113. } // namespace log
  114. } // namespace isc
  115. #endif // __LOGGER_LEVEL_IMPL_H