callbackappender.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // -*- C++ -*-
  2. // Copyright (C) 2015-2017, Vaclav Haisman. All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without modifica-
  5. // tion, are permitted provided that the following conditions are met:
  6. //
  7. // 1. Redistributions of source code must retain the above copyright notice,
  8. // this list of conditions and the following disclaimer.
  9. //
  10. // 2. Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. //
  14. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  15. // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  16. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  17. // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  18. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  19. // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  20. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. /** @file */
  25. #ifndef LOG4CPLUS_CALLBACK_APPENDER_HEADER_
  26. #define LOG4CPLUS_CALLBACK_APPENDER_HEADER_
  27. #include <log4cplus/config.hxx>
  28. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  29. #pragma once
  30. #endif
  31. #include <log4cplus/appender.h>
  32. #include <log4cplus/clogger.h>
  33. namespace log4cplus {
  34. /**
  35. * Send log events to a C function callback.
  36. */
  37. class LOG4CPLUS_EXPORT CallbackAppender
  38. : public Appender {
  39. public:
  40. CallbackAppender();
  41. CallbackAppender(log4cplus_log_event_callback_t callback, void * cookie);
  42. CallbackAppender(const log4cplus::helpers::Properties&);
  43. virtual ~CallbackAppender();
  44. virtual void close();
  45. void setCookie(void *);
  46. void setCallback(log4cplus_log_event_callback_t);
  47. protected:
  48. virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
  49. private:
  50. log4cplus_log_event_callback_t callback;
  51. void * cookie;
  52. // Disallow copying of instances of this class
  53. CallbackAppender(const CallbackAppender&) = delete;
  54. CallbackAppender& operator=(const CallbackAppender&) = delete;
  55. };
  56. } // end namespace log4cplus
  57. #endif // LOG4CPLUS_CALLBACK_APPENDER_HEADER_