logging_info.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright (C) 2014-2015,2017 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_INFO_H
  7. #define DHCPSRV_LOGGING_INFO_H
  8. #include <log/logger_level.h>
  9. #include <log/logger_specification.h>
  10. #include <cc/cfg_to_element.h>
  11. #include <stdint.h>
  12. #include <vector>
  13. namespace isc {
  14. namespace dhcp {
  15. /// @brief Defines single logging destination
  16. ///
  17. /// This structure is used to keep log4cplus configuration parameters.
  18. struct LoggingDestination : public isc::data::CfgToElement {
  19. /// @brief defines logging destination output
  20. ///
  21. /// Values accepted are: stdout, stderr, syslog, syslog:name.
  22. /// Any other destination will be considered a file name.
  23. std::string output_;
  24. /// @brief Maximum number of log files in rotation
  25. int maxver_;
  26. /// @brief Maximum log file size
  27. uint64_t maxsize_;
  28. /// @brief Immediate flush
  29. bool flush_;
  30. /// @brief Compares two objects for equality.
  31. ///
  32. /// @param other Object to be compared with this object.
  33. ///
  34. /// @return true if objects are equal, false otherwise.
  35. bool equals(const LoggingDestination& other) const;
  36. /// @brief Default constructor.
  37. LoggingDestination()
  38. : output_("stdout"), maxver_(1), maxsize_(204800), flush_(true) {
  39. }
  40. /// @brief Unparse a configuration object
  41. ///
  42. /// @return a pointer to unparsed configuration
  43. virtual isc::data::ElementPtr toElement() const;
  44. };
  45. /// @brief structure that describes one logging entry
  46. ///
  47. /// This is a structure that conveys one logger entry configuration.
  48. /// The structure in JSON form has the following syntax:
  49. /// {
  50. /// "name": "*",
  51. /// "output_options": [
  52. /// {
  53. /// "output": "/path/to/the/logfile.log",
  54. /// "maxver": 8,
  55. /// "maxsize": 204800,
  56. /// "flush": true
  57. /// }
  58. /// ],
  59. /// "severity": "WARN",
  60. /// "debuglevel": 99
  61. /// },
  62. struct LoggingInfo : public isc::data::CfgToElement {
  63. /// @brief logging name
  64. std::string name_;
  65. /// @brief describes logging severity
  66. isc::log::Severity severity_;
  67. /// @brief debuglevel (used when severity_ == DEBUG)
  68. ///
  69. /// We use range 0(least verbose)..99(most verbose)
  70. int debuglevel_;
  71. /// @brief specific logging destinations
  72. std::vector<LoggingDestination> destinations_;
  73. /// @brief Default constructor.
  74. LoggingInfo();
  75. /// @brief Removes logging destinations.
  76. void clearDestinations() {
  77. destinations_.clear();
  78. }
  79. /// @brief Compares two objects for equality.
  80. ///
  81. /// @param other An object to be compared with this object.
  82. ///
  83. /// @return true if objects are equal, false otherwise.
  84. bool equals(const LoggingInfo& other) const;
  85. /// @brief Compares two objects for equality.
  86. ///
  87. /// @param other An object to be compared with this object.
  88. ///
  89. /// @return true if objects are equal, false otherwise.
  90. bool operator==(const LoggingInfo& other) const {
  91. return (equals(other));
  92. }
  93. /// @brief Compares two objects for inequality.
  94. ///
  95. /// @param other An object to be compared with this object.
  96. ///
  97. /// @return true if objects are not equal, false otherwise.
  98. bool operator!=(const LoggingInfo& other) const {
  99. return (!equals(other));
  100. }
  101. /// @brief Converts logger configuration to a spec.
  102. isc::log::LoggerSpecification toSpec() const;
  103. /// @brief Unparse a configuration object
  104. ///
  105. /// @return a pointer to unparsed configuration
  106. virtual isc::data::ElementPtr toElement() const;
  107. };
  108. /// @brief storage for logging information in log4cplus format
  109. typedef std::vector<isc::dhcp::LoggingInfo> LoggingInfoStorage;
  110. }
  111. }
  112. #endif // DHCPSRV_LOGGING_INFO_H