logging.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (C) 2014-2015 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 DHCPSRV_LOGGING_H
  7. #define DHCPSRV_LOGGING_H
  8. #include <cc/data.h>
  9. #include <dhcpsrv/srv_config.h>
  10. #include <vector>
  11. namespace isc {
  12. namespace dhcp {
  13. /// @brief Configures log4cplus by translating Kea configuration structures
  14. ///
  15. /// This parser iterates over provided data elements and translates them
  16. /// into values applicable to log4cplus.
  17. ///
  18. /// The data structures converted to JSON format have the following syntax:
  19. /// {
  20. /// "name": "kea",
  21. /// "output_options": [
  22. /// {
  23. /// "output": "/home/thomson/kea-inst/kea-warn.log",
  24. /// "maxver": 8,
  25. /// "maxsize": 204800,
  26. /// "flush": true
  27. /// }
  28. /// ],
  29. /// "severity": "WARN"
  30. /// }
  31. ///
  32. /// This is only an example and actual values may be different.
  33. ///
  34. /// The data structures don't have to originate from JSON. JSON is just a
  35. /// convenient presentation syntax.
  36. ///
  37. /// This class uses @c SrvConfig object to store logging configuration.
  38. class LogConfigParser {
  39. public:
  40. /// @brief Constructor
  41. ///
  42. /// @param storage parsed logging configuration will be stored here
  43. LogConfigParser(const SrvConfigPtr& storage);
  44. /// @brief Parses specified configuration
  45. ///
  46. /// Walks over specified logging configuration JSON structures and store
  47. /// parsed information in config_->logging_info_.
  48. ///
  49. /// @param log_config JSON structures to be parsed (loggers list)
  50. /// @param verbose specifies verbose mode (true forces DEBUG, debuglevel = 99)
  51. void parseConfiguration(const isc::data::ConstElementPtr& log_config,
  52. bool verbose = false);
  53. private:
  54. /// @brief Parses one JSON structure in Logging/loggers" array
  55. ///
  56. /// @param entry JSON structure to be parsed
  57. /// @brief parses one structure in Logging/loggers.
  58. void parseConfigEntry(isc::data::ConstElementPtr entry);
  59. /// @brief Parses output_options structure
  60. ///
  61. /// @ref @c LogConfigParser for an example in JSON format.
  62. ///
  63. /// @param destination parsed parameters will be stored here
  64. /// @param output_options element to be parsed
  65. void parseOutputOptions(std::vector<LoggingDestination>& destination,
  66. isc::data::ConstElementPtr output_options);
  67. /// @brief Configuration is stored here
  68. ///
  69. /// LogConfigParser class uses only config_->logging_info_ field.
  70. SrvConfigPtr config_;
  71. /// @brief Verbose mode
  72. ///
  73. /// When verbose mode is enabled, logging severity is overridden to DEBUG,
  74. /// and debuglevel is always 99.
  75. bool verbose_;
  76. };
  77. } // namespace isc::dhcp
  78. } // namespace isc
  79. #endif // DHCPSRV_LOGGING_H