1 // Module: Log4CPLUS
2 // File: appenderattachableimpl.h
3 // Created: 6/2001
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright (C) Tad E. Smith All rights reserved.
8 //
9 // This software is published under the terms of the Apache Software
10 // License version 1.1, a copy of which has been included with this
11 // distribution in the LICENSE.APL file.
12 //
13
14 /** @file */
15
16 #ifndef _LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_
17 #define _LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_
18
19 #include <log4cplus/config.h>
20 #include <log4cplus/layout.h>
21 #include <log4cplus/tstring.h>
22 #include <log4cplus/helpers/logloguser.h>
23 #include <log4cplus/helpers/pointer.h>
24 #include <log4cplus/helpers/threads.h>
25 #include <log4cplus/spi/appenderattachable.h>
26
27 #include <memory>
28 #include <vector>
29
30
31 namespace log4cplus {
32 namespace helpers {
33
34 /**
35 * This Interface is for attaching Appenders to objects.
36 */
37 class LOG4CPLUS_EXPORT AppenderAttachableImpl
38 : public log4cplus::spi::AppenderAttachable,
39 protected log4cplus::helpers::LogLogUser
40 {
41 public:
42 // Data
43 LOG4CPLUS_MUTEX_PTR_DECLARE appender_list_mutex;
44
45 // Ctors
46 AppenderAttachableImpl();
47
48 // Dtor
49 virtual ~AppenderAttachableImpl();
50
51 // Methods
52 /**
53 * Add an appender. If the appender is already in the list in
54 * won't be added again.
55 */
56 virtual void addAppender(SharedAppenderPtr newAppender);
57
58 /**
59 * Get all previously added appenders as an vectory.
60 */
61 virtual SharedAppenderPtrList getAllAppenders();
62
63 /**
64 * Look for an attached appender named as <code>name</code>.
65 *
66 * <p>Return the appender with that name if in the list. Return null
67 * otherwise.
68 */
69 virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name);
70
71 /**
72 * Remove all previously added appenders.
73 */
74 virtual void removeAllAppenders();
75
76 /**
77 * Remove the appender passed as parameter from the list of appenders.
78 */
79 virtual void removeAppender(SharedAppenderPtr appender);
80
81 /**
82 * Remove the appender with the name passed as parameter from the
83 * list of appenders.
84 */
85 virtual void removeAppender(const log4cplus::tstring& name);
86
87 /**
88 * Call the <code>doAppend</code> method on all attached appenders.
89 */
90 int appendLoopOnAppenders(const spi::InternalLoggingEvent& event) const;
91
92 protected:
93 // Types
94 typedef std::vector<SharedAppenderPtr> ListType;
95
96 // Data
97 /** Array of appenders. */
98 ListType appenderList;
99 }; // end class AppenderAttachableImpl
100
101 } // end namespace helpers
102 } // end namespace log4cplus
103
104 #endif // _LOG4CPLUS_HELPERS_APPENDER_ATTACHABLE_IMPL_HEADER_
syntax highlighted by Code2HTML, v. 0.9.1