You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2005/02/12 04:10:28 UTC
cvs commit: logging-log4j/tests/input/rolling filter1.xml
carnold 2005/02/11 19:10:28
Modified: src/java/org/apache/log4j/rolling RollingFileAppender.java
SizeBasedTriggeringPolicy.java
TimeBasedRollingPolicy.java TriggeringPolicy.java
tests build.xml
Added: src/java/org/apache/log4j/rolling
FilterBasedTriggeringPolicy.java
tests/input/rolling filter1.xml
Log:
Bug 33531: Event filter based rolling
Revision Changes Path
1.22 +2 -2 logging-log4j/src/java/org/apache/log4j/rolling/RollingFileAppender.java
Index: RollingFileAppender.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/RollingFileAppender.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- RollingFileAppender.java 24 Nov 2004 17:17:54 -0000 1.21
+++ RollingFileAppender.java 12 Feb 2005 03:10:27 -0000 1.22
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -159,7 +159,7 @@
protected void subAppend(LoggingEvent event) {
// The rollover check must precede actual writing. This is the
// only correct behavior for time driven triggers.
- if (triggeringPolicy.isTriggeringEvent(activeFile)) {
+ if (triggeringPolicy.isTriggeringEvent(activeFile, event)) {
getLogger().debug("About to rollover");
rollover();
}
1.8 +3 -2 logging-log4j/src/java/org/apache/log4j/rolling/SizeBasedTriggeringPolicy.java
Index: SizeBasedTriggeringPolicy.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/SizeBasedTriggeringPolicy.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SizeBasedTriggeringPolicy.java 9 Dec 2004 13:27:21 -0000 1.7
+++ SizeBasedTriggeringPolicy.java 12 Feb 2005 03:10:27 -0000 1.8
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.apache.log4j.rolling;
import java.io.File;
+import org.apache.log4j.spi.LoggingEvent;
/**
@@ -29,7 +30,7 @@
public class SizeBasedTriggeringPolicy implements TriggeringPolicy {
long maxFileSize = 10 * 1024 * 1024; // let 10 MB the default max size
- public boolean isTriggeringEvent(File file) {
+ public boolean isTriggeringEvent(final File file, final LoggingEvent event) {
//System.out.println("Size"+file.length());
return (file.length() >= maxFileSize);
}
1.19 +3 -3 logging-log4j/src/java/org/apache/log4j/rolling/TimeBasedRollingPolicy.java
Index: TimeBasedRollingPolicy.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/TimeBasedRollingPolicy.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- TimeBasedRollingPolicy.java 6 Jan 2005 19:27:03 -0000 1.18
+++ TimeBasedRollingPolicy.java 12 Feb 2005 03:10:27 -0000 1.19
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
import org.apache.log4j.rolling.helper.FileNamePattern;
import org.apache.log4j.rolling.helper.RollingCalendar;
import org.apache.log4j.rolling.helper.Util;
-
+import org.apache.log4j.spi.LoggingEvent;
import java.io.File;
import java.util.Date;
@@ -256,7 +256,7 @@
}
}
- public boolean isTriggeringEvent(File file) {
+ public boolean isTriggeringEvent(File file, final LoggingEvent event) {
//getLogger().debug("Is triggering event called");
long n = System.currentTimeMillis();
1.6 +7 -5 logging-log4j/src/java/org/apache/log4j/rolling/TriggeringPolicy.java
Index: TriggeringPolicy.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/TriggeringPolicy.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TriggeringPolicy.java 23 Nov 2004 16:30:14 -0000 1.5
+++ TriggeringPolicy.java 12 Feb 2005 03:10:27 -0000 1.6
@@ -1,5 +1,5 @@
/*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,12 +17,12 @@
package org.apache.log4j.rolling;
import java.io.File;
-
+import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.OptionHandler;
/**
* A <code>TriggeringPolicy</code> controls the conditions under which rollover
* occurs. Such conditions include time od day, file size, an
- * external event or a combination thereof.
+ * external event, the log request or a combination thereof.
*
* @author Ceki Gülcü
* @since 1.3
@@ -34,6 +34,8 @@
* Should rolllover be triggered at this time?
*
* @param file A reference to the currently active log file.
- * */
- public boolean isTriggeringEvent(File file);
+ * @param event A reference to the currently event.
+ * @return true if a rollover should occur.
+ */
+ public boolean isTriggeringEvent(final File file, final LoggingEvent event);
}
1.1 logging-log4j/src/java/org/apache/log4j/rolling/FilterBasedTriggeringPolicy.java
Index: FilterBasedTriggeringPolicy.java
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j.rolling;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;
import java.io.File;
/**
* FilterBasedTriggeringPolicy determines if rolling should be triggered
* by evaluating the current message against a set of filters. Unless a
* filter rejects a message, a rolling event will be triggered.
*
* @author Curt Arnold
* @since 1.3
*
*/
public final class FilterBasedTriggeringPolicy implements TriggeringPolicy {
/**
* The first filter in the filter chain. Set to <code>null</code> initially.
*/
private Filter headFilter;
/**
* The last filter in the filter chain.
*/
private Filter tailFilter;
/**
* Creates a new FilterBasedTriggeringPolicy.
*/
public FilterBasedTriggeringPolicy() {
}
/**
* Determines if the event should trigger a rollover.
* @param file rolling file, ignored.
* @param event logging event.
* @return true if event should trigger a rollover.
*
*/
public boolean isTriggeringEvent(final File file, final LoggingEvent event) {
//
// in the abnormal case of no contained filters
// always return true to avoid each logging event
// from having its own file.
if (headFilter == null) {
return false;
}
//
// otherwise loop through the filters
//
for (Filter f = headFilter; f != null; f = f.getNext()) {
switch (f.decide(event)) {
case Filter.DENY:
return false;
case Filter.ACCEPT:
return true;
}
}
return true;
}
/**
* Add a filter to end of the filter list.
* @param newFilter filter to add to end of list.
*/
public void addFilter(Filter newFilter) {
if (headFilter == null) {
headFilter = newFilter;
tailFilter = newFilter;
} else {
tailFilter.setNext(newFilter);
tailFilter = newFilter;
}
}
/**
* Clear the filters chain.
*
*/
public void clearFilters() {
headFilter = null;
tailFilter = null;
}
/**
* Returns the head Filter.
*
*/
public Filter getFilter() {
return headFilter;
}
/**
* Prepares the instance for use.
*/
public void activateOptions() {
for (Filter f = headFilter; f != null; f = f.getNext()) {
f.activateOptions();
}
}
}
1.97 +11 -1 logging-log4j/tests/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/logging-log4j/tests/build.xml,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- build.xml 30 Jan 2005 06:41:16 -0000 1.96
+++ build.xml 12 Feb 2005 03:10:28 -0000 1.97
@@ -208,7 +208,9 @@
<target name="Rolling" depends="Compress,
SizeBasedRolling,
- TimeBasedRolling, Renaming"/>
+ TimeBasedRolling,
+ Renaming,
+ FilterBasedRolling"/>
<!-- ================================================================= -->
@@ -518,6 +520,14 @@
<test name="org.apache.log4j.rolling.TimeBasedRollingTest" />
</junit>
</target>
+
+ <target name="FilterBasedRolling" depends="check, build, cleanOutputDir">
+ <junit printsummary="yes" fork="yes" haltonfailure="yes">
+ <classpath refid="tests.classpath"/>
+ <formatter type="plain" usefile="false"/>
+ <test name="org.apache.log4j.rolling.FilterBasedRollingTest" />
+ </junit>
+ </target>
<target name="MultiplexAppenderTest" depends="check, build, cleanOutputDir">
1.1 logging-log4j/tests/input/rolling/filter1.xml
Index: filter1.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>
<log4j:configuration xmlns:log4j='http://logging.apache.org/' debug="true">
<appender name="ROLLING" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
<param name="activeFileName" value="output/filterBased-test1.log"/>
<param name="fileNamePattern" value="output/filterBased-test1.%i"/>
<param name="minIndex" value="0"/>
</rollingPolicy>
<triggeringPolicy class="org.apache.log4j.rolling.FilterBasedTriggeringPolicy">
<filter class="org.apache.log4j.filter.LevelRangeFilter">
<param name="levelMin" value="info" />
</filter>
</triggeringPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<logger name="org.apache.log4j.rolling.FilterBasedRollingTest" additivity="false">
<appender-ref ref="ROLLING"/>
<level value="debug"/>
</logger>
<root>
<level value="info"/>
<appender-ref ref="CONSOLE"/>
</root>
</log4j:configuration>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org