source: pacpusframework/branches/0.1.x/3rd/apache-log4cxx/include/log4cxx/fileappender.h@ 304

Last change on this file since 304 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 8.6 KB
Line 
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_FILE_APPENDER_H
19#define _LOG4CXX_FILE_APPENDER_H
20
21#include <log4cxx/logger.h>
22#include <log4cxx/logstring.h>
23#include <log4cxx/writerappender.h>
24#include <log4cxx/file.h>
25#include <log4cxx/helpers/pool.h>
26
27namespace log4cxx
28{
29 namespace helpers {
30 class Pool;
31 }
32
33 /**
34 * FileAppender appends log events to a file.
35 *
36 * <p>Support for <code>java.io.Writer</code> and console appending
37 * has been deprecated and then removed. See the replacement
38 * solutions: WriterAppender and ConsoleAppender.
39 */
40 class LOG4CXX_EXPORT FileAppender : public WriterAppender
41 {
42 protected:
43 /** Append to or truncate the file? The default value for this
44 variable is <code>true</code>, meaning that by default a
45 <code>FileAppender</code> will append to an existing file and
46 not truncate it.
47 <p>This option is meaningful only if the FileAppender opens the
48 file.
49 */
50 bool fileAppend;
51
52 /**
53 The name of the log file. */
54 LogString fileName;
55
56 /**
57 Do we do bufferedIO? */
58 bool bufferedIO;
59
60 /**
61 How big should the IO buffer be? Default is 8K. */
62 int bufferSize;
63
64 public:
65 DECLARE_LOG4CXX_OBJECT(FileAppender)
66 BEGIN_LOG4CXX_CAST_MAP()
67 LOG4CXX_CAST_ENTRY(FileAppender)
68 LOG4CXX_CAST_ENTRY_CHAIN(WriterAppender)
69 END_LOG4CXX_CAST_MAP()
70
71 /**
72 The default constructor does not do anything.
73 */
74 FileAppender();
75
76 /**
77 Instantiate a <code>FileAppender</code> and open the file
78 designated by <code>filename</code>. The opened filename will
79 become the output destination for this appender.
80
81 <p>If the <code>append</code> parameter is true, the file will be
82 appended to. Otherwise, the file designated by
83 <code>filename</code> will be truncated before being opened.
84
85 <p>If the <code>bufferedIO</code> parameter is <code>true</code>,
86 then buffered IO will be used to write to the output file.
87
88 */
89 FileAppender(const LayoutPtr& layout, const LogString& filename, bool append,
90 bool bufferedIO, int bufferSize);
91
92 /**
93 Instantiate a FileAppender and open the file designated by
94 <code>filename</code>. The opened filename will become the output
95 destination for this appender.
96
97 <p>If the <code>append</code> parameter is true, the file will be
98 appended to. Otherwise, the file designated by
99 <code>filename</code> will be truncated before being opened.
100 */
101 FileAppender(const LayoutPtr& layout, const LogString& filename, bool append);
102
103 /**
104 Instantiate a FileAppender and open the file designated by
105 <code>filename</code>. The opened filename will become the output
106 destination for this appender.
107
108 <p>The file will be appended to. */
109 FileAppender(const LayoutPtr& layout, const LogString& filename);
110
111 ~FileAppender();
112
113 /**
114 The <b>File</b> property takes a string value which should be the
115 name of the file to append to.
116
117 <p><b>Note that the special values
118 "System.out" or "System.err" are no longer honored.</b>
119
120 <p>Note: Actual opening of the file is made when
121 #activateOptions is called, not when the options are set. */
122 virtual void setFile(const LogString& file);
123
124 /**
125 Sets and <i>opens</i> the file where the log output will
126 go. The specified file must be writable.
127
128 <p>If there was already an opened file, then the previous file
129 is closed first.
130
131 <p><b>Do not use this method directly. To configure a FileAppender
132 or one of its subclasses, set its properties one by one and then
133 call activateOptions.</b>
134
135 @param file The path to the log file.
136 @param append If true will append to fileName. Otherwise will
137 truncate fileName.
138 @param bufferedIO Do we do bufferedIO?
139 @param bufferSize How big should the IO buffer be?
140 @param p memory pool for operation.
141 */
142 virtual void setFile(const LogString& file, bool append,
143 bool bufferedIO, size_t bufferSize,
144 log4cxx::helpers::Pool& p);
145
146 /**
147 Returns the value of the <b>Append</b> option.
148 */
149 inline bool getAppend() const { return fileAppend; }
150
151 /** Returns the value of the <b>File</b> option. */
152 inline LogString getFile() const { return fileName; }
153
154 /**
155 <p>Sets and <i>opens</i> the file where the log output will
156 go. The specified file must be writable.
157
158 <p>If there was already an opened file, then the previous file
159 is closed first.*/
160 void activateOptions(log4cxx::helpers::Pool& p);
161 void setOption(const LogString& option,
162 const LogString& value);
163
164 /**
165 Get the value of the <b>BufferedIO</b> option.
166
167 <p>BufferedIO will significatnly increase performance on heavily
168 loaded systems.
169
170 */
171 inline bool getBufferedIO() const { return bufferedIO; }
172
173 /**
174 Get the size of the IO buffer.
175 */
176 inline int getBufferSize() const { return bufferSize; }
177
178 /**
179 The <b>Append</b> option takes a boolean value. It is set to
180 <code>true</code> by default. If true, then <code>File</code>
181 will be opened in append mode by #setFile (see
182 above). Otherwise, setFile will open
183 <code>File</code> in truncate mode.
184
185 <p>Note: Actual opening of the file is made when
186 #activateOptions is called, not when the options are set.
187 */
188 void setAppend(bool fileAppend1);
189
190 /**
191 The <b>BufferedIO</b> option takes a boolean value. It is set to
192 <code>false</code> by default. If true, then <code>File</code>
193 will be opened in buffered mode.
194
195 BufferedIO will significantly increase performance on heavily
196 loaded systems.
197
198 */
199 void setBufferedIO(bool bufferedIO);
200
201 /**
202 Set the size of the IO buffer.
203 */
204 void setBufferSize(int bufferSize1) { this->bufferSize = bufferSize1; }
205
206 /**
207 * Replaces double backslashes with single backslashes
208 * for compatibility with paths from earlier XML configurations files.
209 * @param name file name
210 * @return corrected file name
211 */
212 static LogString stripDuplicateBackslashes(const LogString& name);
213
214 private:
215 FileAppender(const FileAppender&);
216 FileAppender& operator=(const FileAppender&);
217
218 }; // class FileAppender
219 LOG4CXX_PTR_DEF(FileAppender);
220
221} // namespace log4cxx
222
223#endif
Note: See TracBrowser for help on using the repository browser.