/src/logging-log4cxx/src/main/include/log4cxx/appender.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_H |
19 | | #define _LOG4CXX_APPENDER_H |
20 | | |
21 | | #include <log4cxx/spi/optionhandler.h> |
22 | | #include <log4cxx/helpers/object.h> |
23 | | #include <vector> |
24 | | |
25 | | |
26 | | namespace LOG4CXX_NS |
27 | | { |
28 | | // Forward declarations |
29 | | namespace spi |
30 | | { |
31 | | class LoggingEvent; |
32 | | typedef std::shared_ptr<LoggingEvent> LoggingEventPtr; |
33 | | |
34 | | class Filter; |
35 | | typedef std::shared_ptr<Filter> FilterPtr; |
36 | | |
37 | | class ErrorHandler; |
38 | | typedef std::shared_ptr<ErrorHandler> ErrorHandlerPtr; |
39 | | } |
40 | | |
41 | | class Layout; |
42 | | typedef std::shared_ptr<Layout> LayoutPtr; |
43 | | |
44 | | |
45 | | /** |
46 | | Implement this interface for your own strategies for outputting log |
47 | | statements. |
48 | | */ |
49 | | class LOG4CXX_EXPORT Appender |
50 | | #if LOG4CXX_ABI_VERSION <= 15 |
51 | | : public virtual spi::OptionHandler |
52 | | #else |
53 | | : public spi::OptionHandler |
54 | | #endif |
55 | | { |
56 | | public: |
57 | | DECLARE_ABSTRACT_LOG4CXX_OBJECT(Appender) |
58 | | |
59 | 0 | virtual ~Appender() {} |
60 | | |
61 | | /** |
62 | | Add a filter to the end of the filter list. |
63 | | */ |
64 | | virtual void addFilter(const spi::FilterPtr newFilter) = 0; |
65 | | |
66 | | /** |
67 | | Returns the head Filter. The Filters are organized in a linked list |
68 | | and so all Filters on this Appender are available through the result. |
69 | | |
70 | | @return the head Filter or null, if no Filters are present |
71 | | */ |
72 | | virtual spi::FilterPtr getFilter() const = 0; |
73 | | |
74 | | /** |
75 | | Clear the list of filters by removing all the filters in it. |
76 | | */ |
77 | | virtual void clearFilters() = 0; |
78 | | |
79 | | /** |
80 | | Release any resources allocated within the appender such as file |
81 | | handles, network connections, etc. |
82 | | <p>It is a programming error to append to a closed appender. |
83 | | */ |
84 | | virtual void close() = 0; |
85 | | |
86 | | /** |
87 | | Log in <code>Appender</code> specific way. When appropriate, |
88 | | Loggers will call the <code>doAppend</code> method of appender |
89 | | implementations in order to log. |
90 | | */ |
91 | | #if LOG4CXX_ABI_VERSION <= 15 |
92 | | #define LOG4CXX_APPEND_FORMAL_PARAMETERS const spi::LoggingEventPtr& event, helpers::Pool& p |
93 | 0 | #define LOG4CXX_APPEND_PARAMETERS event, p |
94 | | void doAppend(const spi::LoggingEventPtr& event); |
95 | | /** |
96 | | @deprecated The \c pool parameter is not used and will be removed in a future version. |
97 | | Implement this method for now, but plan to migrate to doAppend() without a helpers::Pool parameter. |
98 | | */ |
99 | | virtual void doAppend(const spi::LoggingEventPtr& event, |
100 | | LOG4CXX_NS::helpers::Pool& pool) = 0; |
101 | | #else |
102 | | #define LOG4CXX_APPEND_FORMAL_PARAMETERS const spi::LoggingEventPtr& event |
103 | | #define LOG4CXX_APPEND_PARAMETERS event |
104 | | virtual void doAppend(const spi::LoggingEventPtr& event) = 0; |
105 | | /** |
106 | | @deprecated The \c pool parameter is not used and will be removed in a future version. |
107 | | */ |
108 | | [[deprecated("Use doAppend() without a Pool parameter instead")]] |
109 | | void doAppend(const spi::LoggingEventPtr& event, helpers::Pool& pool); |
110 | | #endif |
111 | | |
112 | | /** |
113 | | Get the name of this appender. The name uniquely identifies the |
114 | | appender. |
115 | | */ |
116 | | virtual LogString getName() const = 0; |
117 | | |
118 | | |
119 | | /** |
120 | | Set the Layout for this appender. |
121 | | */ |
122 | | virtual void setLayout(const LayoutPtr layout) = 0; |
123 | | |
124 | | /** |
125 | | Returns this appenders layout. |
126 | | */ |
127 | | virtual LayoutPtr getLayout() const = 0; |
128 | | |
129 | | |
130 | | /** |
131 | | Set the name of this appender. The name is used by other |
132 | | components to identify this appender. |
133 | | */ |
134 | | virtual void setName(const LogString& name) = 0; |
135 | | |
136 | | /** |
137 | | Configurators call this method to determine if the appender |
138 | | requires a layout. If this method returns <code>true</code>, |
139 | | meaning that layout is required, then the configurator will |
140 | | configure an layout using the configuration information at its |
141 | | disposal. If this method returns <code>false</code>, meaning that |
142 | | a layout is not required, then layout configuration will be |
143 | | skipped even if there is available layout configuration |
144 | | information at the disposal of the configurator.. |
145 | | |
146 | | <p>In the rather exceptional case, where the appender |
147 | | implementation admits a layout but can also work without it, then |
148 | | the appender should return <code>true</code>. |
149 | | */ |
150 | | virtual bool requiresLayout() const = 0; |
151 | | }; |
152 | | |
153 | | LOG4CXX_PTR_DEF(Appender); |
154 | | LOG4CXX_LIST_DEF(AppenderList, AppenderPtr); |
155 | | |
156 | | } |
157 | | |
158 | | #endif //_LOG4CXX_APPENDER_H |