logging_info.h 3.6 KB

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