logger_manager.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_MANAGER_H
  15. #define __LOGGER_MANAGER_H
  16. #include <log/logger_specification.h>
  17. namespace isc {
  18. namespace log {
  19. class LoggerManagerImpl;
  20. /// \brief Logger Manager
  21. ///
  22. /// The logger manager class exists to process the set of logger specifications
  23. /// and use them to set up the logging in the program appropriately.
  24. ///
  25. /// To isolate the underlying implementation from basic processing, the
  26. /// LoggerManager is implemented using the "pimpl" idiom.
  27. class LoggerManager {
  28. public:
  29. /// \brief Constructor
  30. LoggerManager();
  31. /// \brief Destructor
  32. ~LoggerManager();
  33. /// \brief Process Specifications
  34. ///
  35. /// Given a list of logger specifications, disables all current logging
  36. /// and resets the properties of each logger to that given.
  37. ///
  38. /// \param start Iterator pointing to the start of the collection of
  39. /// logging specifications.
  40. /// \param finish Iterator pointing to the end of the collection of
  41. /// logging specification.
  42. template <typename T>
  43. void process(T start, T finish) {
  44. processInit();
  45. for (T i = start; i != finish; ++i) {
  46. processSpecification(*i);
  47. }
  48. processEnd();
  49. }
  50. /// \brief Process a single specification
  51. ///
  52. /// A convenience function for a single specification.
  53. ///
  54. /// \param spec Specification to process
  55. void process(const LoggerSpecification& spec) {
  56. processInit();
  57. processSpecification(spec);
  58. processEnd();
  59. }
  60. /// \brief Run-Time Initialization
  61. ///
  62. /// Performs run-time initialization of the logger system, in particular
  63. /// supplying the root logger name and name of a replacement message file.
  64. ///
  65. /// This must be the first logging function called in the program.
  66. ///
  67. /// \param root Name of the root logger
  68. /// \param file Name of the local message file.
  69. /// \param severity Severity at which to log
  70. /// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG")
  71. static void init(const std::string& root, const char* file = NULL,
  72. isc::log::Severity severity = isc::log::INFO,
  73. int dbglevel = 0);
  74. private:
  75. /// \brief Initialize Processing
  76. ///
  77. /// Initializes the processing of a list of specifications by resetting all
  78. /// loggers to their defaults. Note that loggers aren't removed as unless
  79. /// a previously-enabled logger is re-enabled, it becomes inactive.
  80. void processInit();
  81. /// \brief Process Logging Specification
  82. ///
  83. /// Processes the given specification. It is assumed at this point that
  84. /// either the logger does not exist or has been made inactive.
  85. void processSpecification(const LoggerSpecification& spec);
  86. /// \brief End Processing
  87. ///
  88. /// Place holder for finish processing.
  89. /// TODO: Check that the root logger has something enabled
  90. void processEnd();
  91. /// \brief Read local message file
  92. ///
  93. /// Reads the local message file into the global dictionary, overwriting
  94. /// existing messages. If the file contained any message IDs not in the
  95. /// dictionary, they are listed in a warning message.
  96. ///
  97. /// \param file Name of the local message file
  98. static void readLocalMessageFile(const char* file);
  99. // Members
  100. LoggerManagerImpl* impl_; ///< Pointer to implementation
  101. };
  102. } // namespace log
  103. } // namespace isc
  104. #endif // __LOGGER_MANAGER_H