asyncappender.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // -*- C++ -*-
  2. // Module: Log4cplus
  3. // File: asyncappender.h
  4. // Created: 1/2009
  5. // Author: Vaclav Haisman
  6. //
  7. //
  8. // Copyright (C) 2009-2017, Vaclav Haisman. All rights reserved.
  9. //
  10. // Redistribution and use in source and binary forms, with or without modifica-
  11. // tion, are permitted provided that the following conditions are met:
  12. //
  13. // 1. Redistributions of source code must retain the above copyright notice,
  14. // this list of conditions and the following disclaimer.
  15. //
  16. // 2. Redistributions in binary form must reproduce the above copyright notice,
  17. // this list of conditions and the following disclaimer in the documentation
  18. // and/or other materials provided with the distribution.
  19. //
  20. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  21. // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  25. // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. //
  31. /** @file */
  32. #ifndef LOG4CPLUS_ASYNCAPPENDER_H
  33. #define LOG4CPLUS_ASYNCAPPENDER_H
  34. #include <log4cplus/config.hxx>
  35. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  36. #pragma once
  37. #endif
  38. #ifndef LOG4CPLUS_SINGLE_THREADED
  39. #include <log4cplus/helpers/queue.h>
  40. #include <log4cplus/appender.h>
  41. #include <log4cplus/thread/threads.h>
  42. #include <log4cplus/helpers/appenderattachableimpl.h>
  43. namespace log4cplus
  44. {
  45. /**
  46. This `Appender` is a wrapper to which other appenders can be attached. The
  47. attached appendres are then appended to from a separate thread which reads
  48. events appended to this appender from a queue.
  49. <h3>Properties</h3>
  50. <dl>
  51. <dt><tt>QueueLimit</tt></dt>
  52. <dd>Events queue size limit. Default is 100.</dd>
  53. </dt>
  54. <dt><tt>Appender</tt></dt>
  55. <dd>`Appender` and its properties to use as sink for logged events.</dd>
  56. </dt>
  57. </dl>
  58. \sa helpers::AppenderAttachableImpl
  59. */
  60. class LOG4CPLUS_EXPORT AsyncAppender
  61. : public Appender
  62. , public helpers::AppenderAttachableImpl
  63. {
  64. public:
  65. AsyncAppender (SharedAppenderPtr const & app, unsigned max_len);
  66. AsyncAppender (helpers::Properties const &);
  67. virtual ~AsyncAppender ();
  68. virtual void close ();
  69. protected:
  70. virtual void append (spi::InternalLoggingEvent const &);
  71. void init_queue_thread (unsigned);
  72. thread::AbstractThreadPtr queue_thread;
  73. thread::QueuePtr queue;
  74. private:
  75. AsyncAppender (AsyncAppender const &);
  76. AsyncAppender & operator = (AsyncAppender const &);
  77. };
  78. typedef helpers::SharedObjectPtr<AsyncAppender> AsyncAppenderPtr;
  79. } // namespace log4cplus
  80. #endif // LOG4CPLUS_SINGLE_THREADED
  81. #endif // LOG4CPLUS_ASYNCAPPENDER_H