logging.h 3.4 KB

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