logging_info.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright (C) 2014 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_INFO_H
  15. #define DHCPSRV_LOGGING_INFO_H
  16. #include <log/logger_level.h>
  17. #include <log/logger_specification.h>
  18. #include <stdint.h>
  19. #include <vector>
  20. namespace isc {
  21. namespace dhcp {
  22. /// @brief Defines single logging destination
  23. ///
  24. /// This structure is used to keep log4cplus configuration parameters.
  25. struct LoggingDestination {
  26. /// @brief defines logging destination output
  27. ///
  28. /// Values accepted are: stdout, stderr, syslog, syslog:name.
  29. /// Any other destination will be considered a file name.
  30. std::string output_;
  31. /// @brief Maximum number of log files in rotation
  32. int maxver_;
  33. /// @brief Maximum log file size
  34. uint64_t maxsize_;
  35. /// @brief Compares two objects for equality.
  36. ///
  37. /// @param other Object to be compared with this object.
  38. ///
  39. /// @return true if objects are equal, false otherwise.
  40. bool equals(const LoggingDestination& other) const;
  41. /// @brief Default constructor.
  42. LoggingDestination()
  43. : output_("stdout"), maxver_(1), maxsize_(204800) {
  44. }
  45. };
  46. /// @brief structure that describes one logging entry
  47. ///
  48. /// This is a structure that conveys one logger entry configuration.
  49. /// The structure in JSON form has the following syntax:
  50. /// {
  51. /// "name": "*",
  52. /// "output_options": [
  53. /// {
  54. /// "output": "/path/to/the/logfile.log",
  55. /// "maxver": 8,
  56. /// "maxsize": 204800
  57. /// }
  58. /// ],
  59. /// "severity": "WARN",
  60. /// "debuglevel": 99
  61. /// },
  62. struct LoggingInfo {
  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. };
  104. /// @brief storage for logging information in log4cplus format
  105. typedef std::vector<isc::dhcp::LoggingInfo> LoggingInfoStorage;
  106. }
  107. }
  108. #endif // DHCPSRV_LOGGING_INFO_H