Coverage Report

Created: 2026-04-12 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
  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> must implement this
48
    method to perform actual logging. See also AppenderSkeleton::doAppend
49
    method.
50
    */
51
    virtual void append(const spi::LoggingEventPtr& event, helpers::Pool& p) = 0;
52
53
    /**
54
    * Compare \c event level against the appender threshold and check that \c event is accepted.
55
    * If \c event is accepted, delegate log output to the subclass implementation of
56
    * the AppenderSkeleton#append method.
57
    * */
58
    void doAppendImpl(const spi::LoggingEventPtr& event, helpers::Pool& pool);
59
60
    /**
61
    * Does no attached filter deny \c event or does an attached filter accept \c event?
62
    */
63
    bool isAccepted(const spi::LoggingEventPtr& event) const;
64
65
  public:
66
    DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderSkeleton)
67
16
    BEGIN_LOG4CXX_CAST_MAP()
68
16
    LOG4CXX_CAST_ENTRY(AppenderSkeleton)
69
16
    LOG4CXX_CAST_ENTRY(Appender)
70
10
    LOG4CXX_CAST_ENTRY(spi::OptionHandler)
71
4
    END_LOG4CXX_CAST_MAP()
72
73
    AppenderSkeleton();
74
    AppenderSkeleton(const LayoutPtr& layout);
75
    virtual ~AppenderSkeleton();
76
77
#if LOG4CXX_ABI_VERSION <= 15
78
    /**
79
    Finalize this appender by calling the derived class'
80
    <code>close</code> method.
81
    */
82
    [[ deprecated( "The derived appender destructor needs to implement its cleanup" ) ]]
83
    void finalize();
84
#endif
85
    /**
86
    \copybrief spi::OptionHandler::activateOptions()
87
88
    No action is performed in this implementation.
89
    */
90
856
    void activateOptions(helpers::Pool& /* pool */) override {}
91
92
    /**
93
    \copybrief spi::OptionHandler::setOption()
94
95
    Supported options | Supported values | Default value |
96
    -------------- | ---------------- | --------------- |
97
    Name      | {any} | - |
98
    Threshold | Trace,Debug,Info,Warn,Error,Fatal,Off,All | All |
99
    */
100
    void setOption(const LogString& option, const LogString& value) override;
101
102
    /**
103
    Add a filter to end of the filter list.
104
    */
105
    void addFilter(const spi::FilterPtr newFilter) override;
106
107
  public:
108
    /**
109
    Clear the filters chain.
110
    */
111
    void clearFilters() override;
112
113
    /**
114
    Return the currently set spi::ErrorHandler for this
115
    Appender.
116
    */
117
    const spi::ErrorHandlerPtr getErrorHandler() const;
118
119
    /**
120
    Returns the head Filter.
121
    */
122
    spi::FilterPtr getFilter() const override;
123
124
    /**
125
    Return the first filter in the filter chain for this
126
    Appender. The return value may be <code>nullptr</code> if no is
127
    filter is set.
128
    */
129
    const spi::FilterPtr getFirstFilter() const;
130
131
    /**
132
    Returns the layout of this appender. The value may be nullptr.
133
    */
134
    LayoutPtr getLayout() const override;
135
136
137
    /**
138
    Returns the name of this Appender.
139
    */
140
    LogString getName() const override;
141
142
    /**
143
    Returns this appenders threshold level. See the #setThreshold
144
    method for the meaning of this option.
145
    */
146
    const LevelPtr getThreshold() const;
147
148
    /**
149
    Check whether the message level is below the appender's
150
    threshold. If there is no threshold set, then the return value is
151
    always <code>true</code>.
152
    */
153
    bool isAsSevereAsThreshold(const LevelPtr& level) const;
154
155
156
    /**
157
    * Call AppenderSkeleton#doAppendImpl after acquiring a lock
158
    * that prevents other threads from concurrently executing AppenderSkeleton#doAppendImpl.
159
    *
160
    * Reimplement this method in your appender if you use a different concurrency control technique.
161
    * */
162
    void doAppend(const spi::LoggingEventPtr& event, helpers::Pool& pool) override;
163
164
    /**
165
    Set the {@link spi::ErrorHandler ErrorHandler} for this Appender.
166
    */
167
    void setErrorHandler(const spi::ErrorHandlerPtr eh);
168
169
    /**
170
    Set the layout for this appender. Note that some appenders have
171
    their own (fixed) layouts or do not use one.
172
    */
173
    void setLayout(const LayoutPtr layout1) override;
174
175
    /**
176
    Set the name of this Appender.
177
    */
178
    void setName(const LogString& name1) override;
179
180
181
    /**
182
    Set the threshold level. All log events with lower level
183
    than the threshold level are ignored by the appender.
184
185
    <p>In configuration files this option is specified by setting the
186
    value of the <b>Threshold</b> option to a level
187
    string, such as "DEBUG", "INFO" and so on.
188
    */
189
    void setThreshold(const LevelPtr& threshold);
190
191
}; // class AppenderSkeleton
192
193
LOG4CXX_PTR_DEF(AppenderSkeleton);
194
}  // namespace log4cxx
195
196
#endif //_LOG4CXX_APPENDER_SKELETON_H