Apache Log4cxx  Version 1.5.0
Loading...
Searching...
No Matches
writerappender.h
Go to the documentation of this file.
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_WRITER_APPENDER_H
19#define _LOG4CXX_WRITER_APPENDER_H
20
23#include <atomic>
24
25namespace LOG4CXX_NS
26{
27
31class LOG4CXX_EXPORT WriterAppender : public AppenderSkeleton
32{
33 protected:
34 struct WriterAppenderPriv;
35 public:
41
42
45 protected:
46#if LOG4CXX_ABI_VERSION <= 15
47 WriterAppender(const LayoutPtr& layout, helpers::WriterPtr& writer);
48 WriterAppender(const LayoutPtr& layout);
49#else
50 WriterAppender(const LayoutPtr& layout, const helpers::WriterPtr& writer = helpers::WriterPtr());
51#endif
52 WriterAppender(std::unique_ptr<WriterAppenderPriv> priv);
53
54 public:
56
61 void activateOptions(helpers::Pool& pool) override;
62
77 void setImmediateFlush(bool value);
81 bool getImmediateFlush() const;
82
95 void append(const spi::LoggingEventPtr& event, helpers::Pool& p) override;
96
97
98 protected:
105 virtual bool checkEntryConditions() const;
106
107
108 public:
115 void close() override;
116
117 protected:
122
129 virtual helpers::WriterPtr createWriter(LOG4CXX_16_CONST helpers::OutputStreamPtr& os);
130
131 public:
143 void setEncoding(const LogString& value);
144
154 void setOption(const LogString& option, const LogString& value) override;
155
166 void setWriter(const helpers::WriterPtr& writer);
167
168 const helpers::WriterPtr getWriter() const;
169
170 bool requiresLayout() const override;
171
172 protected:
176 virtual void subAppend(const spi::LoggingEventPtr& event, helpers::Pool& p);
177
178
182 virtual void writeFooter(helpers::Pool& p);
183
187 virtual void writeHeader(helpers::Pool& p);
188
192 void setWriterInternal(const helpers::WriterPtr& writer);
193
194 private:
195 //
196 // prevent copy and assignment
198 WriterAppender& operator=(const WriterAppender&);
199};
200
202
203} //namespace log4cxx
204
205#endif //_LOG4CXX_WRITER_APPENDER_H
AppenderSkeleton(LOG4CXX_PRIVATE_PTR(AppenderSkeletonPrivate) priv)
WriterAppender appends log events to a standard output stream.
Definition writerappender.h:32
LogString getEncoding() const
The current encoding value.
virtual void writeFooter(helpers::Pool &p)
Write a footer as produced by the embedded layout's Layout::appendFooter method.
void append(const spi::LoggingEventPtr &event, helpers::Pool &p) override
This method is called by the AppenderSkeleton::doAppend method.
virtual void subAppend(const spi::LoggingEventPtr &event, helpers::Pool &p)
Actual writing occurs here.
virtual helpers::WriterPtr createWriter(LOG4CXX_16_CONST helpers::OutputStreamPtr &os)
Returns an OutputStreamWriter when passed an OutputStream.
void setOption(const LogString &option, const LogString &value) override
Set option to value.
void setWriterInternal(const helpers::WriterPtr &writer)
Set the writer.
void setImmediateFlush(bool value)
If the ImmediateFlush option is set to true, the appender will flush at the end of each write.
const helpers::WriterPtr getWriter() const
void closeWriter()
Close the underlying log4cxx::helpers::Writer.
WriterAppender(const LayoutPtr &layout)
void setWriter(const helpers::WriterPtr &writer)
bool requiresLayout() const override
Configurators call this method to determine if the appender requires a layout.
void activateOptions(helpers::Pool &pool) override
Derived appenders should override this method if option structure requires it.
bool getImmediateFlush() const
Returns value of the ImmediateFlush option.
virtual void writeHeader(helpers::Pool &p)
Write a header as produced by the embedded layout's Layout::appendHeader method.
void close() override
Close this appender instance.
WriterAppender(std::unique_ptr< WriterAppenderPriv > priv)
WriterAppender(const LayoutPtr &layout, helpers::WriterPtr &writer)
virtual bool checkEntryConditions() const
This method determines if there is a sense in attempting to append.
void setEncoding(const LogString &value)
Set the encoding to value.
WriterAppender()
This default constructor does nothing.
Definition pool.h:33
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition appender.h:32
std::basic_string< logchar > LogString
Definition logstring.h:60
std::shared_ptr< Layout > LayoutPtr
Definition appender.h:42
LOG4CXX_PTR_DEF(Appender)
#define LOG4CXX_CAST_ENTRY(Interface)
Definition object.h:158
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)
Definition object.h:39
#define END_LOG4CXX_CAST_MAP()
Definition object.h:152
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition object.h:164
#define BEGIN_LOG4CXX_CAST_MAP()
Definition object.h:146
#define LOG4CXX_16_CONST
Definition outputstreamwriter.h:28