Apache log4cxx  Version 0.11.0
writerappender.h
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 
26 #include <log4cxx/appenderskeleton.h>
27 #include <log4cxx/helpers/outputstreamwriter.h>
28 
29 namespace log4cxx
30 {
31 
32 namespace helpers
33 {
34 class Transcoder;
35 }
36 
40 class LOG4CXX_EXPORT WriterAppender : public AppenderSkeleton
41 {
42  private:
56  bool immediateFlush;
57 
63  LogString encoding;
64 
68  log4cxx::helpers::WriterPtr writer;
69 
70 
71  public:
72  DECLARE_ABSTRACT_LOG4CXX_OBJECT(WriterAppender)
73  BEGIN_LOG4CXX_CAST_MAP()
74  LOG4CXX_CAST_ENTRY(WriterAppender)
75  LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
76  END_LOG4CXX_CAST_MAP()
77 
78 
81  protected:
82  WriterAppender(const LayoutPtr& layout,
83  log4cxx::helpers::WriterPtr& writer);
84  WriterAppender(const LayoutPtr& layout);
85 
86  public:
87  ~WriterAppender();
88 
93  virtual void activateOptions(log4cxx::helpers::Pool& pool);
94 
109  void setImmediateFlush(bool value);
113  bool getImmediateFlush() const
114  {
115  return immediateFlush;
116  }
117 
130  virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
131 
132 
133  protected:
140  virtual bool checkEntryConditions() const;
141 
142 
143  public:
150  virtual void close();
151 
152  protected:
156  void closeWriter();
157 
164  virtual log4cxx::helpers::WriterPtr createWriter(
165  log4cxx::helpers::OutputStreamPtr& os);
166 
167  public:
168  LogString getEncoding() const;
169  void setEncoding(const LogString& value);
170  void setOption(const LogString& option,
171  const LogString& value);
172 
185  void setWriter(const log4cxx::helpers::WriterPtr& writer);
186 #ifdef LOG4CXX_MULTI_PROCESS
187  const log4cxx::helpers::WriterPtr getWriter()
188  {
189  return writer;
190  };
191 #endif
192 
193  virtual bool requiresLayout() const;
194 
195  protected:
199  virtual void subAppend(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
200 
201 
205  virtual void writeFooter(log4cxx::helpers::Pool& p);
206 
210  virtual void writeHeader(log4cxx::helpers::Pool& p);
211 
212  private:
213  //
214  // prevent copy and assignment
216  WriterAppender& operator=(const WriterAppender&);
217 };
218 
219 LOG4CXX_PTR_DEF(WriterAppender);
220 
221 } //namespace log4cxx
222 
223 #if defined(_MSC_VER)
224  #pragma warning ( pop )
225 #endif
226 
227 #endif //_LOG4CXX_WRITER_APPENDER_H
Implementation base class for all appenders.
Definition: appenderskeleton.h:45
WriterAppender appends log events to a standard output stream.
Definition: writerappender.h:40
bool getImmediateFlush() const
Returns value of the ImmediateFlush option.
Definition: writerappender.h:113
Definition: pool.h:32
Definition: appender.h:33