logger_level_impl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef LOGGER_LEVEL_IMPL_H
  7. #define LOGGER_LEVEL_IMPL_H
  8. #include <log4cplus/logger.h>
  9. #include <log4cplus/version.h>
  10. #include <log/logger_level.h>
  11. namespace isc {
  12. namespace log {
  13. /// \brief Implementation aspects of logging levels
  14. ///
  15. /// This extends the log4cplus level set to allow 100 debug levels.
  16. ///
  17. /// First some terminology, as the use of the term "level" gets confusing. The
  18. /// code and comments here use the term "level" in two contexts:
  19. ///
  20. /// Logging level: The category of messages to log. By default log4cplus
  21. /// defines the following logging levels: OFF_LOG_LEVEL, FATAL_LOG_LEVEL,
  22. /// ERROR_LOG_LEVEL, WARN_LOG_LEVEL, INFO_LOG_LEVEL, DEBUG_LOG_LEVEL,
  23. /// TRACE_LOG_LEVEL, ALL_LOG_LEVEL (which here will be abbreviated OFF, FATAL
  24. /// etc.). Within the context of Kea, OFF, TRACE and ALL are not used
  25. /// and the idea of DEBUG has been extended, as will be seen below. In
  26. /// Kea terms, this is known as "severity"; the "logging level" usage will
  27. /// usually be used when talking about log4cplus aspects of the idea (as
  28. /// log4cplus uses that terminology).
  29. ///
  30. /// Debug level: This is a number that ranges from 0 to 99 and is used by the
  31. /// application to control the detail of debug output. A value of 0 gives the
  32. /// highest-level debug output; a value of 99 gives the most verbose and most
  33. /// detailed. Debug messages (or whatever debug level) are only ever output
  34. /// when the logging level is set to DEBUG. (Note that the numbers 0 and 99
  35. /// are not hard-coded - they are the constants MIN_DEBUG_LEVEL and
  36. /// MAX_DEBUG_LEVEL.)
  37. ///
  38. /// With log4cplus, the various logging levels have a numeric value associated
  39. /// with them, such that FATAL > ERROR > WARNING etc. This suggests that the
  40. /// idea of debug levels can be incorporated into the existing logging level
  41. /// scheme by assigning them appropriate numeric values, i.e.
  42. ///
  43. /// WARNING > INFO > DEBUG > DEBUG - 1 > DEBUG - 2 > ... > DEBUG - 99
  44. ///
  45. /// Setting a numeric level of DEBUG enables the basic messages; setting higher
  46. /// debug levels (corresponding to lower numeric logging levels) will enable
  47. /// progressively more messages. The lowest debug level (0) is chosen such that
  48. /// it corresponds to the default level of DEBUG.
  49. ///
  50. /// This class comprises nothing more than static methods to aid the conversion
  51. /// of logging levels between log4cplus and Kea, and to register those
  52. /// levels with log4cplus.
  53. class LoggerLevelImpl {
  54. public:
  55. typedef log4cplus::tstring LogLevelString;
  56. /// \brief Convert Kea level to log4cplus logging level
  57. ///
  58. /// Converts the Kea severity level into a log4cplus logging level.
  59. /// If the severity is DEBUG, the current Kea debug level is taken
  60. /// into account when doing the conversion.
  61. ///
  62. /// \param level Kea severity and debug level
  63. ///
  64. /// \return Equivalent log4cplus logging level.
  65. static
  66. log4cplus::LogLevel convertFromBindLevel(const isc::log::Level& level);
  67. /// \brief Convert log4cplus logging level to Kea logging level
  68. ///
  69. /// Converts the log4cplus log level into a Kea severity level.
  70. /// The log4cplus log level may be non-standard in which case it is
  71. /// encoding a Kea debug level as well.
  72. ///
  73. /// \param loglevel log4cplus log level
  74. ///
  75. /// \return Equivalent Kea severity and debug level
  76. static
  77. isc::log::Level convertToBindLevel(const log4cplus::LogLevel loglevel);
  78. /// \brief Convert string to log4cplus logging level
  79. ///
  80. /// Kea extends the set of logging levels in log4cplus with a group
  81. /// of debug levels. These are given names DEBUG0 through DEBUG99 (with
  82. /// DEBUG0 being equivalent to DEBUG, the standard log level. If the name
  83. /// is DEBUGn but n lies outside the range of debug levels, debug level
  84. /// specifies is coerced to the nearest valid value. If the string is just
  85. /// not recognized, a NOT_SET_LOG_LEVEL is returned.
  86. ///
  87. /// \param level String representing the logging level.
  88. ///
  89. /// \return Corresponding log4cplus log level
  90. static
  91. log4cplus::LogLevel logLevelFromString(const log4cplus::tstring& level);
  92. /// \brief Convert log level to string
  93. ///
  94. /// If the log level is one of the extended debug levels, the string DEBUG
  95. /// is returned, otherwise the empty string.
  96. ///
  97. /// \param level Extended logging level
  98. ///
  99. /// \return Equivalent string.
  100. static LogLevelString logLevelToString(log4cplus::LogLevel level);
  101. /// \brief Initialize extended logging levels
  102. ///
  103. /// This must be called once, after log4cplus has been initialized. It
  104. /// registers the level/string converter functions.
  105. static void init();
  106. };
  107. } // namespace log
  108. } // namespace isc
  109. #endif // LOGGER_LEVEL_IMPL_H