StringQueueAppender.hh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * StringQueueAppender.hh
  3. *
  4. * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
  5. * Copyright 2000, Bastiaan Bakker. All rights reserved.
  6. *
  7. * See the COPYING file for the terms of usage and distribution.
  8. */
  9. #ifndef _LOG4CPP_STRINGQUEUEAPPENDER_HH
  10. #define _LOG4CPP_STRINGQUEUEAPPENDER_HH
  11. #include <log4cpp/Portability.hh>
  12. #include <string>
  13. #include <queue>
  14. #include <log4cpp/LayoutAppender.hh>
  15. LOG4CPP_NS_BEGIN
  16. /**
  17. * This class puts log messages in an in-memory queue. Its primary use
  18. * is in test cases, but it may be useful elsewhere as well.
  19. *
  20. * @since 0.2.4
  21. **/
  22. class LOG4CPP_EXPORT StringQueueAppender : public LayoutAppender {
  23. public:
  24. StringQueueAppender(const std::string& name);
  25. virtual ~StringQueueAppender();
  26. virtual bool reopen();
  27. virtual void close();
  28. /**
  29. * Return the current size of the message queue.
  30. * Shorthand for getQueue().size().
  31. * @returns the queue size
  32. **/
  33. virtual size_t queueSize() const;
  34. /**
  35. * Return the queue to which the Appends adds messages.
  36. * @returns the message queue
  37. **/
  38. virtual std::queue<std::string>& getQueue();
  39. /**
  40. * Return the queue to which the Appends adds messages.
  41. * @returns the message queue
  42. **/
  43. virtual const std::queue<std::string>& getQueue() const;
  44. /**
  45. * Pop the oldest log message from the front of the queue.
  46. * @returns the oldest log message
  47. **/
  48. virtual std::string popMessage();
  49. protected:
  50. /**
  51. * Appends the LoggingEvent to the queue.
  52. * @param event the LoggingEvent to layout and append to the queue.
  53. **/
  54. virtual void _append(const LoggingEvent& event);
  55. std::queue<std::string> _queue;
  56. };
  57. LOG4CPP_NS_END
  58. #endif // _LOG4CPP_STRINGQUEUEAPPENDER_HH