You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.5 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: appenderattachableimpl.h
  4. // Created: 6/2001
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2001-2010 Tad E. Smith
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_
  23. #define LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/tstring.h>
  29. #include <log4cplus/helpers/pointer.h>
  30. #include <log4cplus/spi/appenderattachable.h>
  31. #include <log4cplus/thread/syncprims.h>
  32. #include <memory>
  33. #include <vector>
  34. namespace log4cplus {
  35. namespace helpers {
  36. /**
  37. * This Interface is for attaching Appenders to objects.
  38. */
  39. class LOG4CPLUS_EXPORT AppenderAttachableImpl
  40. : public log4cplus::spi::AppenderAttachable
  41. {
  42. public:
  43. // Data
  44. thread::Mutex appender_list_mutex;
  45. // Ctors
  46. AppenderAttachableImpl();
  47. // Dtor
  48. virtual ~AppenderAttachableImpl();
  49. // Methods
  50. /**
  51. * Add an appender. If the appender is already in the list in
  52. * won't be added again.
  53. */
  54. virtual void addAppender(SharedAppenderPtr newAppender);
  55. /**
  56. * Get all previously added appenders as an vectory.
  57. */
  58. virtual SharedAppenderPtrList getAllAppenders();
  59. /**
  60. * Look for an attached appender named as <code>name</code>.
  61. *
  62. * Return the appender with that name if in the list. Return null
  63. * otherwise.
  64. */
  65. virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name);
  66. /**
  67. * Remove all previously added appenders.
  68. */
  69. virtual void removeAllAppenders();
  70. /**
  71. * Remove the appender passed as parameter from the list of appenders.
  72. */
  73. virtual void removeAppender(SharedAppenderPtr appender);
  74. /**
  75. * Remove the appender with the name passed as parameter from the
  76. * list of appenders.
  77. */
  78. virtual void removeAppender(const log4cplus::tstring& name);
  79. /**
  80. * Call the <code>doAppend</code> method on all attached appenders.
  81. */
  82. int appendLoopOnAppenders(const spi::InternalLoggingEvent& event) const;
  83. protected:
  84. // Types
  85. typedef std::vector<SharedAppenderPtr> ListType;
  86. // Data
  87. /** Array of appenders. */
  88. ListType appenderList;
  89. private:
  90. AppenderAttachableImpl(AppenderAttachableImpl const &);
  91. AppenderAttachableImpl & operator = (AppenderAttachableImpl const &);
  92. }; // end class AppenderAttachableImpl
  93. } // end namespace helpers
  94. } // end namespace log4cplus
  95. #endif // LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_