output_option.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (C) 2011 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 __OUTPUT_OPTION_H
  15. #define __OUTPUT_OPTION_H
  16. #include <stdint.h>
  17. #include <stdlib.h>
  18. #include <string>
  19. /// \brief Logger Output Option
  20. ///
  21. /// The logging configuration options are a list of logger specifications, each
  22. /// with one or more output options. This class represents an output option;
  23. /// one or more of these are attached to a LoggerSpecification object which is
  24. /// then passed to the LoggerManager to configure the logger.
  25. ///
  26. /// Although there are three distinct output types (console, file, syslog) and
  27. /// the options for each do not really overlap. Although it is tempting to
  28. /// define a base OutputOption class and derive a class for each type
  29. /// (ConsoleOutputOptions etc.), it would be messy to use in practice. At
  30. /// some point the exact class would have to be known to get the class-specific
  31. /// options and the (pointer to) the base class cast to the appropriate type.
  32. /// Instead, this "struct" contains the union of all output options; it is up
  33. /// to the caller to cherry-pick the members it needs.
  34. ///
  35. /// One final note: this object holds data and does no computation. For this
  36. /// reason, it is a "struct" and members are accessed directly instead of
  37. /// through methods.
  38. namespace isc {
  39. namespace log {
  40. struct OutputOption {
  41. /// Destinations. Prefixed "DEST_" to avoid problems with the C stdio.h
  42. /// FILE type.
  43. typedef enum {
  44. DEST_CONSOLE = 0,
  45. DEST_FILE = 1,
  46. DEST_SYSLOG = 2
  47. } Destination;
  48. /// If console, stream on which messages are output
  49. typedef enum {
  50. STR_STDOUT = 1,
  51. STR_STDERR = 2
  52. } Stream;
  53. /// \brief Constructor
  54. OutputOption() : destination(DEST_CONSOLE), stream(STR_STDERR),
  55. flush(true), facility("LOCAL0"), filename(""),
  56. maxsize(0), maxver(0)
  57. {}
  58. /// Members.
  59. Destination destination; ///< Where the output should go
  60. Stream stream; ///< stdout/stderr if console output
  61. bool flush; ///< true to flush after each message
  62. std::string facility; ///< syslog facility
  63. std::string filename; ///< Filename if file output
  64. size_t maxsize; ///< 0 if no maximum size
  65. unsigned int maxver; ///< Maximum versions (none if <= 0)
  66. };
  67. OutputOption::Destination getDestination(const std::string& dest_str);
  68. OutputOption::Stream getStream(const std::string& stream_str);
  69. } // namespace log
  70. } // namespace isc
  71. #endif // __OUTPUT_OPTION_H