logging_info.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_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 Immediate flush
  36. bool flush_;
  37. /// @brief Compares two objects for equality.
  38. ///
  39. /// @param other Object to be compared with this object.
  40. ///
  41. /// @return true if objects are equal, false otherwise.
  42. bool equals(const LoggingDestination& other) const;
  43. /// @brief Default constructor.
  44. LoggingDestination()
  45. : output_("stdout"), maxver_(1), maxsize_(204800), flush_(true) {
  46. }
  47. };
  48. /// @brief structure that describes one logging entry
  49. ///
  50. /// This is a structure that conveys one logger entry configuration.
  51. /// The structure in JSON form has the following syntax:
  52. /// {
  53. /// "name": "*",
  54. /// "output_options": [
  55. /// {
  56. /// "output": "/path/to/the/logfile.log",
  57. /// "maxver": 8,
  58. /// "maxsize": 204800,
  59. /// "flush": true
  60. /// }
  61. /// ],
  62. /// "severity": "WARN",
  63. /// "debuglevel": 99
  64. /// },
  65. struct LoggingInfo {
  66. /// @brief logging name
  67. std::string name_;
  68. /// @brief describes logging severity
  69. isc::log::Severity severity_;
  70. /// @brief debuglevel (used when severity_ == DEBUG)
  71. ///
  72. /// We use range 0(least verbose)..99(most verbose)
  73. int debuglevel_;
  74. /// @brief specific logging destinations
  75. std::vector<LoggingDestination> destinations_;
  76. /// @brief Default constructor.
  77. LoggingInfo();
  78. /// @brief Removes logging destinations.
  79. void clearDestinations() {
  80. destinations_.clear();
  81. }
  82. /// @brief Compares two objects for equality.
  83. ///
  84. /// @param other An object to be compared with this object.
  85. ///
  86. /// @return true if objects are equal, false otherwise.
  87. bool equals(const LoggingInfo& other) const;
  88. /// @brief Compares two objects for equality.
  89. ///
  90. /// @param other An object to be compared with this object.
  91. ///
  92. /// @return true if objects are equal, false otherwise.
  93. bool operator==(const LoggingInfo& other) const {
  94. return (equals(other));
  95. }
  96. /// @brief Compares two objects for inequality.
  97. ///
  98. /// @param other An object to be compared with this object.
  99. ///
  100. /// @return true if objects are not equal, false otherwise.
  101. bool operator!=(const LoggingInfo& other) const {
  102. return (!equals(other));
  103. }
  104. /// @brief Converts logger configuration to a spec.
  105. isc::log::LoggerSpecification toSpec() const;
  106. };
  107. /// @brief storage for logging information in log4cplus format
  108. typedef std::vector<isc::dhcp::LoggingInfo> LoggingInfoStorage;
  109. }
  110. }
  111. #endif // DHCPSRV_LOGGING_INFO_H