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_FILTER_BASED_TRIGGERING_POLICY_H)
|
---|
19 | #define _LOG4CXX_ROLLING_FILTER_BASED_TRIGGERING_POLICY_H
|
---|
20 |
|
---|
21 | #include <log4cxx/rolling/triggeringpolicy.h>
|
---|
22 | #include <log4cxx/spi/filter.h>
|
---|
23 |
|
---|
24 | namespace log4cxx {
|
---|
25 |
|
---|
26 | class File;
|
---|
27 |
|
---|
28 | namespace helpers {
|
---|
29 | class Pool;
|
---|
30 | }
|
---|
31 |
|
---|
32 |
|
---|
33 | namespace rolling {
|
---|
34 |
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * FilterBasedTriggeringPolicy determines if rolling should be triggered
|
---|
38 | * by evaluating the current message against a set of filters. Unless a
|
---|
39 | * filter rejects a message, a rolling event will be triggered.
|
---|
40 | *
|
---|
41 | *
|
---|
42 | *
|
---|
43 | *
|
---|
44 | */
|
---|
45 | class LOG4CXX_EXPORT FilterBasedTriggeringPolicy : public TriggeringPolicy {
|
---|
46 |
|
---|
47 | DECLARE_LOG4CXX_OBJECT(FilterBasedTriggeringPolicy)
|
---|
48 | BEGIN_LOG4CXX_CAST_MAP()
|
---|
49 | LOG4CXX_CAST_ENTRY(FilterBasedTriggeringPolicy)
|
---|
50 | LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy)
|
---|
51 | END_LOG4CXX_CAST_MAP()
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * The first filter in the filter chain. Set to <code>null</code> initially.
|
---|
55 | */
|
---|
56 | log4cxx::spi::FilterPtr headFilter;
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * The last filter in the filter chain.
|
---|
60 | */
|
---|
61 | log4cxx::spi::FilterPtr tailFilter;
|
---|
62 |
|
---|
63 | public:
|
---|
64 | /**
|
---|
65 | * Creates a new FilterBasedTriggeringPolicy.
|
---|
66 | */
|
---|
67 | FilterBasedTriggeringPolicy();
|
---|
68 | virtual ~FilterBasedTriggeringPolicy();
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Determines if a rollover may be appropriate at this time. If
|
---|
72 | * true is returned, RolloverPolicy.rollover will be called but it
|
---|
73 | * can determine that a rollover is not warranted.
|
---|
74 | *
|
---|
75 | * @param appender A reference to the appender.
|
---|
76 | * @param event A reference to the currently event.
|
---|
77 | * @param filename The filename for the currently active log file.
|
---|
78 | * @param fileLength Length of the file in bytes.
|
---|
79 | * @return true if a rollover should occur.
|
---|
80 | */
|
---|
81 | virtual bool isTriggeringEvent(
|
---|
82 | Appender* appender,
|
---|
83 | const log4cxx::spi::LoggingEventPtr& event,
|
---|
84 | const LogString& filename,
|
---|
85 | size_t fileLength);
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Add a filter to end of the filter list.
|
---|
89 | * @param newFilter filter to add to end of list.
|
---|
90 | */
|
---|
91 | void addFilter(const log4cxx::spi::FilterPtr& newFilter);
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Clear the filters chain.
|
---|
95 | *
|
---|
96 | */
|
---|
97 | void clearFilters();
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Returns the head Filter.
|
---|
101 | *
|
---|
102 | */
|
---|
103 | log4cxx::spi::FilterPtr& getFilter();
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Prepares the instance for use.
|
---|
107 | */
|
---|
108 | void activateOptions(log4cxx::helpers::Pool&);
|
---|
109 |
|
---|
110 | void setOption(const LogString& option, const LogString& value);
|
---|
111 | };
|
---|
112 |
|
---|
113 | LOG4CXX_PTR_DEF(FilterBasedTriggeringPolicy);
|
---|
114 |
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | #endif
|
---|