Apache log4cxx Version 0.13.0
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
21#if defined(_MSC_VER)
22 #pragma warning ( push )
23 #pragma warning ( disable: 4231 4251 4275 4786 )
24#endif
25
28#include <log4cxx/boost-std-configuration.h>
29#include <atomic>
30
31namespace log4cxx
32{
33
34namespace helpers
35{
36class Transcoder;
37}
38
42class LOG4CXX_EXPORT WriterAppender : public AppenderSkeleton
43{
44 private:
58 std::atomic<bool> immediateFlush;
59
65 LogString encoding;
66
70 log4cxx::helpers::WriterPtr writer;
71
72
73 public:
79
80
83 protected:
85 log4cxx::helpers::WriterPtr& writer);
86 WriterAppender(const LayoutPtr& layout);
87
88 public:
90
95 virtual void activateOptions(log4cxx::helpers::Pool& pool);
96
111 void setImmediateFlush(bool value);
115 bool getImmediateFlush() const
116 {
117 return immediateFlush;
118 }
119
132 virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
133
134
135 protected:
142 virtual bool checkEntryConditions() const;
143
144
145 public:
152 virtual void close();
153
154 protected:
159
166 virtual log4cxx::helpers::WriterPtr createWriter(
167 log4cxx::helpers::OutputStreamPtr& os);
168
169 public:
171 void setEncoding(const LogString& value);
172 void setOption(const LogString& option,
173 const LogString& value);
174
187 void setWriter(const log4cxx::helpers::WriterPtr& writer);
188#ifdef LOG4CXX_MULTI_PROCESS
189 const log4cxx::helpers::WriterPtr getWriter()
190 {
191 return writer;
192 };
193#endif
194
195 virtual bool requiresLayout() const;
196
197 protected:
202
203
208
213
217 void setWriterInternal(const log4cxx::helpers::WriterPtr& writer);
218
219 private:
220 //
221 // prevent copy and assignment
223 WriterAppender& operator=(const WriterAppender&);
224};
225
227
228} //namespace log4cxx
229
230#if defined(_MSC_VER)
231 #pragma warning ( pop )
232#endif
233
234#endif //_LOG4CXX_WRITER_APPENDER_H
Implementation base class for all appenders.
Definition: appenderskeleton.h:46
WriterAppender appends log events to a standard output stream.
Definition: writerappender.h:43
virtual void close()
Close this appender instance.
LogString getEncoding() const
virtual void writeHeader(log4cxx::helpers::Pool &p)
Write a header as produced by the embedded layout's Layout::appendHeader method.
void setWriter(const log4cxx::helpers::WriterPtr &writer)
virtual void append(const spi::LoggingEventPtr &event, log4cxx::helpers::Pool &p)
This method is called by the AppenderSkeleton::doAppend method.
void closeWriter()
Close the underlying log4cxx::helpers::Writer.
void setOption(const LogString &option, const LogString &value)
Set option to value.
virtual bool requiresLayout() const
Configurators call this method to determine if the appender requires a layout.
virtual void subAppend(const spi::LoggingEventPtr &event, log4cxx::helpers::Pool &p)
Actual writing occurs here.
virtual log4cxx::helpers::WriterPtr createWriter(log4cxx::helpers::OutputStreamPtr &os)
Returns an OutputStreamWriter when passed an OutputStream.
virtual void writeFooter(log4cxx::helpers::Pool &p)
Write a footer as produced by the embedded layout's Layout::appendFooter method.
void setWriterInternal(const log4cxx::helpers::WriterPtr &writer)
Set the writer.
virtual bool checkEntryConditions() const
This method determines if there is a sense in attempting to append.
void setEncoding(const LogString &value)
Definition: pool.h:33
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:38
Definition: messagehandler.h:23
std::basic_string< logchar > LogString
Definition: logstring.h:66
std::shared_ptr< Layout > LayoutPtr
Definition: appender.h:48
LOG4CXX_PTR_DEF(Appender)
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)
Definition: object.h:26
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:159
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141