source: pacpusframework/branches/0.0.x/3rd/apache-log4cxx/include/log4cxx/appenderskeleton.h@ 180

Last change on this file since 180 was 2, checked in by sgosseli, 12 years ago

Add 3rd party libraries (log4cxx).

File size: 7.4 KB
Line 
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#if defined(_MSC_VER)
22#pragma warning ( push )
23#pragma warning ( disable: 4231 4251 4275 4786 )
24#endif
25
26
27#include <log4cxx/appender.h>
28#include <log4cxx/layout.h>
29#include <log4cxx/spi/errorhandler.h>
30#include <log4cxx/spi/filter.h>
31#include <log4cxx/helpers/objectimpl.h>
32#include <log4cxx/helpers/mutex.h>
33#include <log4cxx/helpers/pool.h>
34#include <log4cxx/level.h>
35
36
37namespace log4cxx
38{
39 /**
40 * Implementation base class for all appenders.
41 *
42 * This class provides the code for common functionality, such as
43 * support for threshold filtering and support for general filters.
44 * */
45 class LOG4CXX_EXPORT AppenderSkeleton :
46 public virtual Appender,
47 public virtual helpers::ObjectImpl
48 {
49 protected:
50 /** The layout variable does not need to be set if the appender
51 implementation has its own layout. */
52 LayoutPtr layout;
53
54 /** Appenders are named. */
55 LogString name;
56
57 /**
58 There is no level threshold filtering by default. */
59 LevelPtr threshold;
60
61 /**
62 It is assumed and enforced that errorHandler is never null.
63 */
64 spi::ErrorHandlerPtr errorHandler;
65
66 /** The first filter in the filter chain. Set to <code>null</code>
67 initially. */
68 spi::FilterPtr headFilter;
69
70 /** The last filter in the filter chain. */
71 spi::FilterPtr tailFilter;
72
73 /**
74 Is this appender closed?
75 */
76 bool closed;
77
78 log4cxx::helpers::Pool pool;
79 log4cxx::helpers::Mutex mutex;
80
81 public:
82 DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderSkeleton)
83 BEGIN_LOG4CXX_CAST_MAP()
84 LOG4CXX_CAST_ENTRY(Appender)
85 LOG4CXX_CAST_ENTRY(spi::OptionHandler)
86 END_LOG4CXX_CAST_MAP()
87
88 AppenderSkeleton();
89 AppenderSkeleton(const LayoutPtr& layout);
90
91 void addRef() const;
92 void releaseRef() const;
93
94 /**
95 Finalize this appender by calling the derived class'
96 <code>close</code> method.
97 */
98 void finalize();
99
100 /**
101 Derived appenders should override this method if option structure
102 requires it.
103 */
104 virtual void activateOptions(log4cxx::helpers::Pool& /* pool */) {}
105 virtual void setOption(const LogString& option, const LogString& value);
106
107 /**
108 Add a filter to end of the filter list.
109 */
110 void addFilter(const spi::FilterPtr& newFilter) ;
111
112 /**
113 Subclasses of <code>AppenderSkeleton</code> should implement this
114 method to perform actual logging. See also AppenderSkeleton::doAppend
115 method.
116 */
117 protected:
118 virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) = 0;
119
120 /**
121 Clear the filters chain.
122 */
123 public:
124 void clearFilters();
125
126 /**
127 Return the currently set spi::ErrorHandler for this
128 Appender.
129 */
130 const spi::ErrorHandlerPtr& getErrorHandler() const { return errorHandler; }
131
132 /**
133 Returns the head Filter.
134 */
135 spi::FilterPtr getFilter() const { return headFilter; }
136
137 /**
138 Return the first filter in the filter chain for this
139 Appender. The return value may be <code>0</code> if no is
140 filter is set.
141 */
142 const spi::FilterPtr& getFirstFilter() const { return headFilter; }
143
144 /**
145 Returns the layout of this appender. The value may be 0.
146 */
147 LayoutPtr getLayout() const { return layout; }
148
149
150 /**
151 Returns the name of this Appender.
152 */
153 LogString getName() const { return name; }
154
155 /**
156 Returns this appenders threshold level. See the #setThreshold
157 method for the meaning of this option.
158 */
159 const LevelPtr& getThreshold() { return threshold; }
160
161 /**
162 Check whether the message level is below the appender's
163 threshold. If there is no threshold set, then the return value is
164 always <code>true</code>.
165 */
166 bool isAsSevereAsThreshold(const LevelPtr& level) const;
167
168
169 /**
170 * This method performs threshold checks and invokes filters before
171 * delegating actual logging to the subclasses specific
172 * AppenderSkeleton#append method.
173 * */
174 void doAppend(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool);
175
176 /**
177 Set the {@link spi::ErrorHandler ErrorHandler} for this Appender.
178 */
179 void setErrorHandler(const spi::ErrorHandlerPtr& eh);
180
181 /**
182 Set the layout for this appender. Note that some appenders have
183 their own (fixed) layouts or do not use one. For example, the
184 {@link net::SocketAppender SocketAppender} ignores the layout set
185 here.
186 */
187 void setLayout(const LayoutPtr& layout1) { this->layout = layout1; }
188
189 /**
190 Set the name of this Appender.
191 */
192 void setName(const LogString& name1) { this->name.assign(name1); }
193
194
195 /**
196 Set the threshold level. All log events with lower level
197 than the threshold level are ignored by the appender.
198
199 <p>In configuration files this option is specified by setting the
200 value of the <b>Threshold</b> option to a level
201 string, such as "DEBUG", "INFO" and so on.
202 */
203 void setThreshold(const LevelPtr& threshold);
204
205 }; // class AppenderSkeleton
206} // namespace log4cxx
207
208#if defined(_MSC_VER)
209#pragma warning ( pop )
210#endif
211
212
213#endif //_LOG4CXX_APPENDER_SKELETON_H
Note: See TracBrowser for help on using the repository browser.