Coverage Report

Created: 2025-08-26 06:48

/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
  public virtual spi::OptionHandler
51
{
52
  public:
53
    DECLARE_ABSTRACT_LOG4CXX_OBJECT(Appender)
54
55
534
    virtual ~Appender() {}
56
57
    /**
58
     Add a filter to the end of the filter list.
59
    */
60
    virtual void addFilter(const spi::FilterPtr newFilter) = 0;
61
62
    /**
63
     Returns the head Filter. The Filters are organized in a linked list
64
     and so all Filters on this Appender are available through the result.
65
66
     @return the head Filter or null, if no Filters are present
67
     */
68
    virtual spi::FilterPtr getFilter() const = 0;
69
70
    /**
71
     Clear the list of filters by removing all the filters in it.
72
    */
73
    virtual void clearFilters() = 0;
74
75
    /**
76
     Release any resources allocated within the appender such as file
77
     handles, network connections, etc.
78
     <p>It is a programming error to append to a closed appender.
79
    */
80
    virtual void close() = 0;
81
82
    /**
83
     Log in <code>Appender</code> specific way. When appropriate,
84
     Loggers will call the <code>doAppend</code> method of appender
85
     implementations in order to log.
86
    */
87
    virtual void doAppend(const spi::LoggingEventPtr& event,
88
      LOG4CXX_NS::helpers::Pool& pool) = 0;
89
90
91
    /**
92
     Get the name of this appender. The name uniquely identifies the
93
     appender.
94
    */
95
    virtual LogString getName() const = 0;
96
97
98
    /**
99
     Set the Layout for this appender.
100
    */
101
    virtual void setLayout(const LayoutPtr layout) = 0;
102
103
    /**
104
     Returns this appenders layout.
105
    */
106
    virtual LayoutPtr getLayout() const = 0;
107
108
109
    /**
110
     Set the name of this appender. The name is used by other
111
     components to identify this appender.
112
    */
113
    virtual void setName(const LogString& name) = 0;
114
115
    /**
116
     Configurators call this method to determine if the appender
117
     requires a layout. If this method returns <code>true</code>,
118
     meaning that layout is required, then the configurator will
119
     configure an layout using the configuration information at its
120
     disposal.  If this method returns <code>false</code>, meaning that
121
     a layout is not required, then layout configuration will be
122
     skipped even if there is available layout configuration
123
     information at the disposal of the configurator..
124
125
     <p>In the rather exceptional case, where the appender
126
     implementation admits a layout but can also work without it, then
127
     the appender should return <code>true</code>.
128
    */
129
    virtual bool requiresLayout() const = 0;
130
};
131
132
LOG4CXX_PTR_DEF(Appender);
133
LOG4CXX_LIST_DEF(AppenderList, AppenderPtr);
134
135
}
136
137
#endif //_LOG4CXX_APPENDER_H