AppenderSkeleton.hh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * AppenderSkeleton.hh
  3. *
  4. * Copyright 2001, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
  5. * Copyright 2001, Bastiaan Bakker. All rights reserved.
  6. *
  7. * See the COPYING file for the terms of usage and distribution.
  8. */
  9. #ifndef _LOG4CPP_APPENDERSKELETON_HH
  10. #define _LOG4CPP_APPENDERSKELETON_HH
  11. #include <log4cpp/Portability.hh>
  12. #include <log4cpp/Appender.hh>
  13. #include <log4cpp/Filter.hh>
  14. LOG4CPP_NS_BEGIN
  15. /**
  16. * AppenderSkeleton is a helper class, simplifying implementation of
  17. * Appenders: it already takes care of handling of Thresholds and
  18. * Filters.
  19. **/
  20. class LOG4CPP_EXPORT AppenderSkeleton : public Appender {
  21. protected:
  22. /**
  23. * Constructor for AppenderSkeleton. Will only be used in
  24. * getAppender() (and in derived classes of course).
  25. * @param name The name of this Appender.
  26. **/
  27. AppenderSkeleton(const std::string& name);
  28. public:
  29. /**
  30. * Destructor for AppenderSkeleton.
  31. **/
  32. virtual ~AppenderSkeleton();
  33. /**
  34. * Log in Appender specific way.
  35. * @param event The LoggingEvent to log.
  36. **/
  37. virtual void doAppend(const LoggingEvent& event);
  38. /**
  39. * Reopens the output destination of this Appender, e.g. the logfile
  40. * or TCP socket.
  41. * @returns false if an error occured during reopening, true otherwise.
  42. **/
  43. virtual bool reopen();
  44. /**
  45. * Release any resources allocated within the appender such as file
  46. * handles, network connections, etc.
  47. **/
  48. virtual void close() = 0;
  49. /**
  50. * Check if the appender uses a layout.
  51. *
  52. * @returns true if the appender implementation requires a layout.
  53. **/
  54. virtual bool requiresLayout() const = 0;
  55. /**
  56. * Set the Layout for this appender.
  57. * @param layout The layout to use.
  58. **/
  59. virtual void setLayout(Layout* layout) = 0;
  60. /**
  61. * Set the threshold priority of this Appender. The Appender will not
  62. * appender LoggingEvents with a priority lower than the threshold.
  63. * Use Priority::NOTSET to disable threshold checking.
  64. * @param priority The priority to set.
  65. **/
  66. virtual void setThreshold(Priority::Value priority);
  67. /**
  68. * Get the threshold priority of this Appender.
  69. * @returns the threshold
  70. **/
  71. virtual Priority::Value getThreshold();
  72. /**
  73. * Set a Filter for this appender.
  74. **/
  75. virtual void setFilter(Filter* filter);
  76. /**
  77. * Get the Filter for this appender.
  78. * @returns the filter, or NULL if no filter has been set.
  79. **/
  80. virtual Filter* getFilter();
  81. protected:
  82. /**
  83. * Log in Appender specific way. Subclasses of Appender should
  84. * implement this method to perform actual logging.
  85. * @param event The LoggingEvent to log.
  86. **/
  87. virtual void _append(const LoggingEvent& event) = 0;
  88. private:
  89. Priority::Value _threshold;
  90. Filter* _filter;
  91. private:
  92. // suppress assignment operator
  93. AppenderSkeleton & operator=(const AppenderSkeleton &);
  94. };
  95. LOG4CPP_NS_END
  96. #endif // _LOG4CPP_APPENDERSKELETON_HH