Coverage Report

Created: 2025-10-10 06:52

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