/src/logging-log4cxx/src/main/include/log4cxx/appenderskeleton.h
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #ifndef _LOG4CXX_APPENDER_SKELETON_H |
19 | | #define _LOG4CXX_APPENDER_SKELETON_H |
20 | | |
21 | | #include <log4cxx/appender.h> |
22 | | #include <log4cxx/layout.h> |
23 | | #include <log4cxx/spi/errorhandler.h> |
24 | | #include <log4cxx/spi/filter.h> |
25 | | #include <log4cxx/helpers/object.h> |
26 | | #include <log4cxx/helpers/pool.h> |
27 | | #include <log4cxx/level.h> |
28 | | |
29 | | namespace LOG4CXX_NS |
30 | | { |
31 | | |
32 | | /** |
33 | | * Implementation base class for all appenders. |
34 | | * |
35 | | * This class provides the code for common functionality, such as |
36 | | * support for threshold filtering and support for general filters. |
37 | | * */ |
38 | | class LOG4CXX_EXPORT AppenderSkeleton |
39 | | #if LOG4CXX_ABI_VERSION <= 15 |
40 | | : public virtual Appender |
41 | | , public virtual helpers::Object |
42 | | #else |
43 | | : public Appender |
44 | | #endif |
45 | | { |
46 | | protected: |
47 | | LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(AppenderSkeletonPrivate, m_priv) |
48 | | AppenderSkeleton(LOG4CXX_PRIVATE_PTR(AppenderSkeletonPrivate) priv); |
49 | | |
50 | | /** |
51 | | Subclasses of <code>AppenderSkeleton</code> must implement this |
52 | | method to perform actual logging. See also AppenderSkeleton::doAppend |
53 | | method. |
54 | | */ |
55 | | virtual void append( LOG4CXX_APPEND_FORMAL_PARAMETERS ) = 0; |
56 | | |
57 | | /** |
58 | | * Compare \c event level against the appender threshold and check that \c event is accepted. |
59 | | * If \c event is accepted, delegate log output to the subclass implementation of |
60 | | * the AppenderSkeleton#append method. |
61 | | * */ |
62 | | void doAppendImpl( LOG4CXX_APPEND_FORMAL_PARAMETERS ); |
63 | | /** |
64 | | * Does no attached filter deny \c event or does an attached filter accept \c event? |
65 | | */ |
66 | | bool isAccepted(const spi::LoggingEventPtr& event) const; |
67 | | |
68 | | public: |
69 | | DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderSkeleton) |
70 | 0 | BEGIN_LOG4CXX_CAST_MAP() |
71 | 0 | LOG4CXX_CAST_ENTRY(AppenderSkeleton) |
72 | 0 | LOG4CXX_CAST_ENTRY(Appender) |
73 | 0 | LOG4CXX_CAST_ENTRY(spi::OptionHandler) |
74 | 0 | END_LOG4CXX_CAST_MAP() |
75 | | |
76 | | AppenderSkeleton(); |
77 | | AppenderSkeleton(const LayoutPtr& layout); |
78 | | virtual ~AppenderSkeleton(); |
79 | | |
80 | | #if LOG4CXX_ABI_VERSION <= 15 |
81 | | /** |
82 | | Finalize this appender by calling the derived class' |
83 | | <code>close</code> method. |
84 | | */ |
85 | | [[ deprecated( "The derived appender destructor needs to implement its cleanup" ) ]] |
86 | | void finalize(); |
87 | | #endif |
88 | | |
89 | | using spi::OptionHandler::activateOptions; |
90 | | /** |
91 | | \copybrief spi::OptionHandler::activateOptions() |
92 | | |
93 | | No action is performed in this implementation. |
94 | | |
95 | | @deprecated The \c pool parameter is not required and will be removed in a future version. |
96 | | */ |
97 | | void activateOptions( LOG4CXX_ACTIVATE_OPTIONS_FORMAL_PARAMETERS ) override; |
98 | | |
99 | | /** |
100 | | \copybrief spi::OptionHandler::setOption() |
101 | | |
102 | | Supported options | Supported values | Default value | |
103 | | -------------- | ---------------- | --------------- | |
104 | | Name | {any} | - | |
105 | | Threshold | Trace,Debug,Info,Warn,Error,Fatal,Off,All | All | |
106 | | */ |
107 | | void setOption(const LogString& option, const LogString& value) override; |
108 | | |
109 | | /** |
110 | | Add a filter to end of the filter list. |
111 | | */ |
112 | | void addFilter(const spi::FilterPtr newFilter) override; |
113 | | |
114 | | public: |
115 | | /** |
116 | | Clear the filters chain. |
117 | | */ |
118 | | void clearFilters() override; |
119 | | |
120 | | /** |
121 | | Return the currently set spi::ErrorHandler for this |
122 | | Appender. |
123 | | */ |
124 | | const spi::ErrorHandlerPtr getErrorHandler() const; |
125 | | |
126 | | /** |
127 | | Returns the head Filter. |
128 | | */ |
129 | | spi::FilterPtr getFilter() const override; |
130 | | |
131 | | /** |
132 | | Return the first filter in the filter chain for this |
133 | | Appender. The return value may be <code>nullptr</code> if no is |
134 | | filter is set. |
135 | | */ |
136 | | const spi::FilterPtr getFirstFilter() const; |
137 | | |
138 | | /** |
139 | | Returns the layout of this appender. The value may be nullptr. |
140 | | */ |
141 | | LayoutPtr getLayout() const override; |
142 | | |
143 | | |
144 | | /** |
145 | | Returns the name of this Appender. |
146 | | */ |
147 | | LogString getName() const override; |
148 | | |
149 | | /** |
150 | | Returns this appenders threshold level. See the #setThreshold |
151 | | method for the meaning of this option. |
152 | | */ |
153 | | const LevelPtr getThreshold() const; |
154 | | |
155 | | /** |
156 | | Check whether the message level is below the appender's |
157 | | threshold. If there is no threshold set, then the return value is |
158 | | always <code>true</code>. |
159 | | */ |
160 | | bool isAsSevereAsThreshold(const LevelPtr& level) const; |
161 | | |
162 | | |
163 | | /** |
164 | | * Call AppenderSkeleton#doAppendImpl after acquiring a lock |
165 | | * that prevents other threads from concurrently executing AppenderSkeleton#doAppendImpl. |
166 | | * |
167 | | * Reimplement this method in your appender if you use a different concurrency control technique. |
168 | | * */ |
169 | | void doAppend( LOG4CXX_APPEND_FORMAL_PARAMETERS ) override; |
170 | | |
171 | | /** |
172 | | Set the {@link spi::ErrorHandler ErrorHandler} for this Appender. |
173 | | */ |
174 | | void setErrorHandler(const spi::ErrorHandlerPtr eh); |
175 | | |
176 | | /** |
177 | | Set the layout for this appender. Note that some appenders have |
178 | | their own (fixed) layouts or do not use one. |
179 | | */ |
180 | | void setLayout(const LayoutPtr layout1) override; |
181 | | |
182 | | /** |
183 | | Set the name of this Appender. |
184 | | */ |
185 | | void setName(const LogString& name1) override; |
186 | | |
187 | | |
188 | | /** |
189 | | Set the threshold level. All log events with lower level |
190 | | than the threshold level are ignored by the appender. |
191 | | |
192 | | <p>In configuration files this option is specified by setting the |
193 | | value of the <b>Threshold</b> option to a level |
194 | | string, such as "DEBUG", "INFO" and so on. |
195 | | */ |
196 | | void setThreshold(const LevelPtr& threshold); |
197 | | |
198 | | }; // class AppenderSkeleton |
199 | | |
200 | | LOG4CXX_PTR_DEF(AppenderSkeleton); |
201 | | } // namespace log4cxx |
202 | | |
203 | | #endif //_LOG4CXX_APPENDER_SKELETON_H |