/src/logging-log4cxx/src/main/include/log4cxx/appenderskeleton.h
Line | Count | Source (jump to first uncovered 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 | | #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 | | public virtual Appender, |
40 | | public virtual helpers::Object |
41 | | { |
42 | | protected: |
43 | | LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(AppenderSkeletonPrivate, m_priv) |
44 | | AppenderSkeleton(LOG4CXX_PRIVATE_PTR(AppenderSkeletonPrivate) priv); |
45 | | |
46 | | /** |
47 | | Subclasses of <code>AppenderSkeleton</code> should implement this |
48 | | method to perform actual logging. See also AppenderSkeleton::doAppend |
49 | | method. |
50 | | */ |
51 | | virtual void append(const spi::LoggingEventPtr& event, LOG4CXX_NS::helpers::Pool& p) = 0; |
52 | | |
53 | | void doAppendImpl(const spi::LoggingEventPtr& event, LOG4CXX_NS::helpers::Pool& pool); |
54 | | |
55 | | public: |
56 | | DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderSkeleton) |
57 | 7 | BEGIN_LOG4CXX_CAST_MAP() |
58 | 7 | LOG4CXX_CAST_ENTRY(AppenderSkeleton) |
59 | 7 | LOG4CXX_CAST_ENTRY(Appender) |
60 | 4 | LOG4CXX_CAST_ENTRY(spi::OptionHandler) |
61 | 1 | END_LOG4CXX_CAST_MAP() |
62 | | |
63 | | AppenderSkeleton(); |
64 | | AppenderSkeleton(const LayoutPtr& layout); |
65 | | virtual ~AppenderSkeleton(); |
66 | | |
67 | | /** |
68 | | Finalize this appender by calling the derived class' |
69 | | <code>close</code> method. |
70 | | */ |
71 | | void finalize(); |
72 | | |
73 | | /** |
74 | | \copybrief spi::OptionHandler::activateOptions() |
75 | | |
76 | | No action is performed in this implementation. |
77 | | */ |
78 | 0 | void activateOptions(helpers::Pool& /* pool */) override {} |
79 | | |
80 | | /** |
81 | | \copybrief spi::OptionHandler::setOption() |
82 | | |
83 | | Supported options | Supported values | Default value |
84 | | -------------- | ---------------- | --------------- |
85 | | Threshold | Trace,Debug,Info,Warn,Error,Fatal,Off,All | All |
86 | | */ |
87 | | void setOption(const LogString& option, const LogString& value) override; |
88 | | |
89 | | /** |
90 | | Add a filter to end of the filter list. |
91 | | */ |
92 | | void addFilter(const spi::FilterPtr newFilter) override; |
93 | | |
94 | | public: |
95 | | /** |
96 | | Clear the filters chain. |
97 | | */ |
98 | | void clearFilters() override; |
99 | | |
100 | | /** |
101 | | Return the currently set spi::ErrorHandler for this |
102 | | Appender. |
103 | | */ |
104 | | const spi::ErrorHandlerPtr getErrorHandler() const; |
105 | | |
106 | | /** |
107 | | Returns the head Filter. |
108 | | */ |
109 | | spi::FilterPtr getFilter() const override; |
110 | | |
111 | | /** |
112 | | Return the first filter in the filter chain for this |
113 | | Appender. The return value may be <code>nullptr</code> if no is |
114 | | filter is set. |
115 | | */ |
116 | | const spi::FilterPtr getFirstFilter() const; |
117 | | |
118 | | /** |
119 | | Returns the layout of this appender. The value may be nullptr. |
120 | | */ |
121 | | LayoutPtr getLayout() const override; |
122 | | |
123 | | |
124 | | /** |
125 | | Returns the name of this Appender. |
126 | | */ |
127 | | LogString getName() const override; |
128 | | |
129 | | /** |
130 | | Returns this appenders threshold level. See the #setThreshold |
131 | | method for the meaning of this option. |
132 | | */ |
133 | | const LevelPtr getThreshold() const; |
134 | | |
135 | | /** |
136 | | Check whether the message level is below the appender's |
137 | | threshold. If there is no threshold set, then the return value is |
138 | | always <code>true</code>. |
139 | | */ |
140 | | bool isAsSevereAsThreshold(const LevelPtr& level) const; |
141 | | |
142 | | |
143 | | /** |
144 | | * This method performs threshold checks and invokes filters before |
145 | | * delegating actual logging to the subclasses specific |
146 | | * AppenderSkeleton#append method. |
147 | | * */ |
148 | | void doAppend(const spi::LoggingEventPtr& event, helpers::Pool& pool) override; |
149 | | |
150 | | /** |
151 | | Set the {@link spi::ErrorHandler ErrorHandler} for this Appender. |
152 | | */ |
153 | | void setErrorHandler(const spi::ErrorHandlerPtr eh); |
154 | | |
155 | | /** |
156 | | Set the layout for this appender. Note that some appenders have |
157 | | their own (fixed) layouts or do not use one. |
158 | | */ |
159 | | void setLayout(const LayoutPtr layout1) override; |
160 | | |
161 | | /** |
162 | | Set the name of this Appender. |
163 | | */ |
164 | | void setName(const LogString& name1) override; |
165 | | |
166 | | |
167 | | /** |
168 | | Set the threshold level. All log events with lower level |
169 | | than the threshold level are ignored by the appender. |
170 | | |
171 | | <p>In configuration files this option is specified by setting the |
172 | | value of the <b>Threshold</b> option to a level |
173 | | string, such as "DEBUG", "INFO" and so on. |
174 | | */ |
175 | | void setThreshold(const LevelPtr& threshold); |
176 | | |
177 | | }; // class AppenderSkeleton |
178 | | } // namespace log4cxx |
179 | | |
180 | | #endif //_LOG4CXX_APPENDER_SKELETON_H |