source: pacpusframework/trunk/3rd/apache-log4cxx/include/log4cxx/rolling/fixedwindowrollingpolicy.h@ 178

Last change on this file since 178 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: 4.9 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#if !defined(_LOG4CXX_ROLLING_FIXED_WINDOW_ROLLING_POLICY_H)
19#define _LOG4CXX_ROLLING_FIXED_WINDOW_ROLLING_POLICY_H
20
21#include <log4cxx/rolling/rollingpolicybase.h>
22
23
24
25
26namespace log4cxx {
27
28 namespace helpers {
29 class Pool;
30 }
31
32 namespace rolling {
33
34
35/**
36 * When rolling over, <code>FixedWindowRollingPolicy</code> renames files
37 * according to a fixed window algorithm as described below.
38 *
39 * <p>The <b>ActiveFileName</b> property, which is required, represents the name
40 * of the file where current logging output will be written.
41 * The <b>FileNamePattern</b> option represents the file name pattern for the
42 * archived (rolled over) log files. If present, the <b>FileNamePattern</b>
43 * option must include an integer token, that is the string "%i" somwhere
44 * within the pattern.
45 *
46 * <p>Let <em>max</em> and <em>min</em> represent the values of respectively
47 * the <b>MaxIndex</b> and <b>MinIndex</b> options. Let "foo.log" be the value
48 * of the <b>ActiveFile</b> option and "foo.%i.log" the value of
49 * <b>FileNamePattern</b>. Then, when rolling over, the file
50 * <code>foo.<em>max</em>.log</code> will be deleted, the file
51 * <code>foo.<em>max-1</em>.log</code> will be renamed as
52 * <code>foo.<em>max</em>.log</code>, the file <code>foo.<em>max-2</em>.log</code>
53 * renamed as <code>foo.<em>max-1</em>.log</code>, and so on,
54 * the file <code>foo.<em>min+1</em>.log</code> renamed as
55 * <code>foo.<em>min+2</em>.log</code>. Lastly, the active file <code>foo.log</code>
56 * will be renamed as <code>foo.<em>min</em>.log</code> and a new active file name
57 * <code>foo.log</code> will be created.
58 *
59 * <p>Given that this rollover algorithm requires as many file renaming
60 * operations as the window size, large window sizes are discouraged. The
61 * current implementation will automatically reduce the window size to 12 when
62 * larger values are specified by the user.
63 *
64 *
65 *
66 *
67 * */
68 class LOG4CXX_EXPORT FixedWindowRollingPolicy : public RollingPolicyBase {
69 DECLARE_LOG4CXX_OBJECT(FixedWindowRollingPolicy)
70 BEGIN_LOG4CXX_CAST_MAP()
71 LOG4CXX_CAST_ENTRY(FixedWindowRollingPolicy)
72 LOG4CXX_CAST_ENTRY_CHAIN(RollingPolicyBase)
73 END_LOG4CXX_CAST_MAP()
74
75 int minIndex;
76 int maxIndex;
77 bool explicitActiveFile;
78
79 /**
80 * It's almost always a bad idea to have a large window size, say over 12.
81 */
82 enum { MAX_WINDOW_SIZE = 12 };
83
84 bool purge(int purgeStart, int maxIndex, log4cxx::helpers::Pool& p) const;
85
86 public:
87
88 FixedWindowRollingPolicy();
89
90 void activateOptions(log4cxx::helpers::Pool& p);
91 void setOption(const LogString& option,
92 const LogString& value);
93
94 void rollover();
95
96 int getMaxIndex() const;
97
98 int getMinIndex() const;
99
100 void setMaxIndex(int newVal);
101 void setMinIndex(int newVal);
102
103
104/**
105* Initialize the policy and return any initial actions for rolling file appender.
106*
107* @param file current value of RollingFileAppender::getFile().
108* @param append current value of RollingFileAppender::getAppend().
109* @param p pool used for any required memory allocations.
110* @return Description of the initialization, may be null to indicate
111* no initialization needed.
112* @throws SecurityException if denied access to log files.
113*/
114virtual RolloverDescriptionPtr initialize(
115const LogString& file, const bool append, log4cxx::helpers::Pool& p);
116
117/**
118* Prepare for a rollover. This method is called prior to
119* closing the active log file, performs any necessary
120* preliminary actions and describes actions needed
121* after close of current log file.
122*
123* @param activeFile file name for current active log file.
124* @param p pool used for any required memory allocations.
125* @return Description of pending rollover, may be null to indicate no rollover
126* at this time.
127* @throws SecurityException if denied access to log files.
128*/
129virtual RolloverDescriptionPtr rollover(const LogString& activeFile, log4cxx::helpers::Pool& p);
130
131protected:
132 log4cxx::pattern::PatternMap getFormatSpecifiers() const;
133
134 };
135
136 LOG4CXX_PTR_DEF(FixedWindowRollingPolicy);
137
138 }
139}
140
141#endif
Note: See TracBrowser for help on using the repository browser.