Apache log4cxx  Version 0.12.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 
31 namespace log4cxx
32 {
33 
34 namespace helpers
35 {
36 class Transcoder;
37 }
38 
42 class 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:
84  WriterAppender(const LayoutPtr& layout,
85  log4cxx::helpers::WriterPtr& writer);
86  WriterAppender(const LayoutPtr& layout);
87 
88  public:
89  ~WriterAppender();
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:
158  void closeWriter();
159 
166  virtual log4cxx::helpers::WriterPtr createWriter(
167  log4cxx::helpers::OutputStreamPtr& os);
168 
169  public:
170  LogString getEncoding() const;
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:
201  virtual void subAppend(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
202 
203 
207  virtual void writeFooter(log4cxx::helpers::Pool& p);
208 
212  virtual void writeHeader(log4cxx::helpers::Pool& p);
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
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)
Definition: object.h:26
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:148
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:142
Implementation base class for all appenders.
Definition: appenderskeleton.h:43
LOG4CXX_PTR_DEF(AppenderAttachableImpl)
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:37
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:136
WriterAppender appends log events to a standard output stream.
Definition: writerappender.h:42
std::shared_ptr< Layout > LayoutPtr
Definition: appender.h:47
bool getImmediateFlush() const
Returns value of the ImmediateFlush option.
Definition: writerappender.h:115
Definition: pool.h:32
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:154
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66