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/06/02 07:48:57 UTC
cvs commit: logging-log4j/tests/src/java/org/apache/log4j/rolling/helper FileNamePatternTestCase.java
carnold 2005/06/01 22:48:57
Modified: src/java/org/apache/log4j/pattern
ClassNamePatternConverter.java
LoggerPatternConverter.java
LoggingEventPatternConverter.java
src/java/org/apache/log4j/rolling
FixedWindowRollingPolicy.java
RollingFileAppender.java RollingPolicyBase.java
TimeBasedRollingPolicy.java
tests/src/java/org/apache/log4j CoreTestSuite.java
tests/src/java/org/apache/log4j/rolling
FilterBasedRollingTest.java
tests/src/java/org/apache/log4j/rolling/helper
FileNamePatternTestCase.java
Added: src/java/org/apache/log4j/pattern NamePatternConverter.java
tests/src/java/org/apache/log4j/pattern
FormattingInfoTest.java
Removed: src/java/org/apache/log4j/pattern NamedPatternConverter.java
Log:
Bug 34979: Renamed NamedPatConv to NamePatConv, changed protected to private in RollingPolicyBase
Revision Changes Path
1.12 +1 -1 logging-log4j/src/java/org/apache/log4j/pattern/ClassNamePatternConverter.java
Index: ClassNamePatternConverter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/ClassNamePatternConverter.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ClassNamePatternConverter.java 22 May 2005 07:56:22 -0000 1.11
+++ ClassNamePatternConverter.java 2 Jun 2005 05:48:57 -0000 1.12
@@ -27,7 +27,7 @@
* @author Ceki Gülcü
* @since 1.3
*/
-public final class ClassNamePatternConverter extends NamedPatternConverter {
+public final class ClassNamePatternConverter extends NamePatternConverter {
/**
* Private constructor.
* @param options options, may be null.
1.8 +1 -1 logging-log4j/src/java/org/apache/log4j/pattern/LoggerPatternConverter.java
Index: LoggerPatternConverter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/LoggerPatternConverter.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- LoggerPatternConverter.java 22 May 2005 07:56:22 -0000 1.7
+++ LoggerPatternConverter.java 2 Jun 2005 05:48:57 -0000 1.8
@@ -27,7 +27,7 @@
*
* @since 1.3
*/
-public final class LoggerPatternConverter extends NamedPatternConverter {
+public final class LoggerPatternConverter extends NamePatternConverter {
/**
* Singleton.
*/
1.2 +6 -13 logging-log4j/src/java/org/apache/log4j/pattern/LoggingEventPatternConverter.java
Index: LoggingEventPatternConverter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/LoggingEventPatternConverter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LoggingEventPatternConverter.java 22 May 2005 07:56:22 -0000 1.1
+++ LoggingEventPatternConverter.java 2 Jun 2005 05:48:57 -0000 1.2
@@ -20,19 +20,12 @@
/**
-
- <p>PatternConverter is an abtract class that provides the
- formatting functionality that derived classes need.
-
- <p>Conversion specifiers in a conversion patterns are parsed to
- individual PatternConverters. Each of which is responsible for
- converting a logging event in a converter specific manner.
-
- @author <a href="mailto:cakalijp@Maritz.com">James P. Cakalic</a>
- @author Ceki Gülcü
- @author Chris Nokes
-
- @since 1.3
+ * LoggingEventPatternConverter is a base class for pattern converters
+ * that can format information from instances of LoggingEvent.
+ *
+ * @author Curt Arnold
+ *
+ * @since 1.3
*/
public abstract class LoggingEventPatternConverter extends PatternConverter {
/**
1.1 logging-log4j/src/java/org/apache/log4j/pattern/NamePatternConverter.java
Index: NamePatternConverter.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.pattern;
/**
*
* Base class for other pattern converters which can return only parts of their name.
*
* @author Ceki Gülcü
* @author Curt Arnold
*
* @since 1.3
*/
public abstract class NamePatternConverter
extends LoggingEventPatternConverter {
/**
* Abbreviator.
*/
private final NameAbbreviator abbreviator;
/**
* Constructor.
* @param name name of converter.
* @param style style name for associated output.
* @param options options, may be null, first element will be interpreted as an abbreviation pattern.
*/
protected NamePatternConverter(
final String name, final String style, final String[] options) {
super(name, style);
if ((options != null) && (options.length > 0)) {
abbreviator = NameAbbreviator.getAbbreviator(options[0]);
} else {
abbreviator = NameAbbreviator.getDefaultAbbreviator();
}
}
/**
* Abbreviate name in string buffer.
* @param nameStart starting position of name to abbreviate.
* @param buf string buffer containing name.
*/
protected final void abbreviate(final int nameStart, final StringBuffer buf) {
abbreviator.abbreviate(nameStart, buf);
}
}
1.13 +3 -17 logging-log4j/src/java/org/apache/log4j/rolling/FixedWindowRollingPolicy.java
Index: FixedWindowRollingPolicy.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/FixedWindowRollingPolicy.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FixedWindowRollingPolicy.java 25 May 2005 21:16:27 -0000 1.12
+++ FixedWindowRollingPolicy.java 2 Jun 2005 05:48:57 -0000 1.13
@@ -109,13 +109,7 @@
* {@inheritDoc}
*/
public void activateOptions() {
- if (fileNamePatternStr != null) {
- parseFileNamePattern();
- } else {
- getLogger().warn(FNP_NOT_SET);
- getLogger().warn(SEE_FNP_NOT_SET);
- throw new IllegalStateException(FNP_NOT_SET + SEE_FNP_NOT_SET);
- }
+ super.activateOptions();
if (maxIndex < minIndex) {
getLogger().warn(
@@ -131,19 +125,11 @@
getLogger().warn("MaxIndex reduced to {}.", new Integer(maxIndex));
}
- PatternConverter itc = null;
-
- for (int i = 0; i < patternConverters.length; i++) {
- if (patternConverters[i] instanceof IntegerPatternConverter) {
- itc = patternConverters[i];
-
- break;
- }
- }
+ PatternConverter itc = getIntegerPatternConverter();
if (itc == null) {
throw new IllegalStateException(
- "FileNamePattern [" + fileNamePatternStr
+ "FileNamePattern [" + getFileNamePattern()
+ "] does not contain a valid integer format specifier");
}
}
1.30 +2 -0 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.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- RollingFileAppender.java 26 May 2005 06:05:38 -0000 1.29
+++ RollingFileAppender.java 2 Jun 2005 05:48:57 -0000 1.30
@@ -108,6 +108,8 @@
getLogger().warn(
"Please set a rolling policy for the RollingFileAppender named '{}'",
getName());
+
+ return;
}
//
1.8 +48 -4 logging-log4j/src/java/org/apache/log4j/rolling/RollingPolicyBase.java
Index: RollingPolicyBase.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/RollingPolicyBase.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RollingPolicyBase.java 25 May 2005 21:16:27 -0000 1.7
+++ RollingPolicyBase.java 2 Jun 2005 05:48:57 -0000 1.8
@@ -19,6 +19,8 @@
import org.apache.log4j.pattern.FormattingInfo;
import org.apache.log4j.pattern.PatternConverter;
import org.apache.log4j.pattern.PatternParser;
+import org.apache.log4j.pattern.IntegerPatternConverter;
+import org.apache.log4j.pattern.DatePatternConverter;
import org.apache.log4j.spi.ComponentBase;
import org.apache.log4j.spi.OptionHandler;
@@ -37,20 +39,32 @@
*/
public abstract class RollingPolicyBase extends ComponentBase
implements RollingPolicy, OptionHandler {
+ /**
+ * Error message.
+ */
+ private static final String FNP_NOT_SET =
+ "The FileNamePattern option must be set before using RollingPolicy. ";
+
+ /**
+ * Reference for error message.
+ */
+ private static final String SEE_FNP_NOT_SET =
+ "See also http://logging.apache.org/log4j/codes.html#tbr_fnp_not_set";
+
/**
* File name pattern converters.
*/
- protected PatternConverter[] patternConverters;
+ private PatternConverter[] patternConverters;
/**
* File name field specifiers.
*/
- protected FormattingInfo[] patternFields;
+ private FormattingInfo[] patternFields;
/**
* File name pattern.
*/
- protected String fileNamePatternStr;
+ private String fileNamePatternStr;
/**
* Active file name may be null.
@@ -61,7 +75,17 @@
/**
* {@inheritDoc}
*/
- public abstract void activateOptions();
+ public void activateOptions() {
+ // find out period from the filename pattern
+ if (fileNamePatternStr != null) {
+ parseFileNamePattern();
+ } else {
+ getLogger().warn(FNP_NOT_SET);
+ getLogger().warn(SEE_FNP_NOT_SET);
+ throw new IllegalStateException(FNP_NOT_SET + SEE_FNP_NOT_SET);
+ }
+
+ }
/**
* Set file name pattern.
@@ -131,4 +155,24 @@
}
}
}
+
+ protected final PatternConverter getDatePatternConverter() {
+ for (int i = 0; i < patternConverters.length; i++) {
+ if (patternConverters[i] instanceof DatePatternConverter) {
+ return patternConverters[i];
+ }
+ }
+ return null;
+
+ }
+
+ protected final PatternConverter getIntegerPatternConverter() {
+ for (int i = 0; i < patternConverters.length; i++) {
+ if (patternConverters[i] instanceof IntegerPatternConverter) {
+ return patternConverters[i];
+ }
+ }
+ return null;
+ }
+
}
1.25 +3 -29 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.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- TimeBasedRollingPolicy.java 26 May 2005 06:05:38 -0000 1.24
+++ TimeBasedRollingPolicy.java 2 Jun 2005 05:48:57 -0000 1.25
@@ -139,17 +139,6 @@
*/
public final class TimeBasedRollingPolicy extends RollingPolicyBase
implements TriggeringPolicy {
- /**
- * Error message.
- */
- private static final String FNP_NOT_SET =
- "The FileNamePattern option must be set before using TimeBasedRollingPolicy. ";
-
- /**
- * Reference for error message.
- */
- private static final String SEE_FNP_NOT_SET =
- "See also http://logging.apache.org/log4j/codes.html#tbr_fnp_not_set";
/**
* Time for next determination if time for rollover.
@@ -176,28 +165,13 @@
* Prepares instance of use.
*/
public void activateOptions() {
- // find out period from the filename pattern
- if (fileNamePatternStr != null) {
- parseFileNamePattern();
- } else {
- getLogger().warn(FNP_NOT_SET);
- getLogger().warn(SEE_FNP_NOT_SET);
- throw new IllegalStateException(FNP_NOT_SET + SEE_FNP_NOT_SET);
- }
-
- PatternConverter dtc = null;
+ super.activateOptions();
- for (int i = 0; i < patternConverters.length; i++) {
- if (patternConverters[i] instanceof DatePatternConverter) {
- dtc = patternConverters[i];
-
- break;
- }
- }
+ PatternConverter dtc = getDatePatternConverter();
if (dtc == null) {
throw new IllegalStateException(
- "FileNamePattern [" + fileNamePatternStr
+ "FileNamePattern [" + getFileNamePattern()
+ "] does not contain a valid date format specifier");
}
1.4 +1 -0 logging-log4j/tests/src/java/org/apache/log4j/CoreTestSuite.java
Index: CoreTestSuite.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/CoreTestSuite.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CoreTestSuite.java 22 May 2005 07:56:23 -0000 1.3
+++ CoreTestSuite.java 2 Jun 2005 05:48:57 -0000 1.4
@@ -37,6 +37,7 @@
s.addTestSuite(org.apache.log4j.pattern.NameAbbreviatorTest.class);
s.addTestSuite(org.apache.log4j.pattern.PatternParserTest.class);
s.addTestSuite(org.apache.log4j.rolling.helper.FileNamePatternTestCase.class);
+ s.addTestSuite(org.apache.log4j.pattern.FormattingInfoTest.class);
return s;
}
}
1.1 logging-log4j/tests/src/java/org/apache/log4j/pattern/FormattingInfoTest.java
Index: FormattingInfoTest.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.pattern;
import junit.framework.TestCase;
/**
* Tests for FormattingInfo.
*
* @author Curt Arnold
* @since 1.3
*
*/
public class FormattingInfoTest extends TestCase {
/**
* Create a new instance.
*
* @param name test name
*/
public FormattingInfoTest(final String name) {
super(name);
}
/**
* Check that getDefault does not return null.
*
*/
public void testGetDefault() {
FormattingInfo field = FormattingInfo.getDefault();
assertNotNull(field);
assertEquals(0, field.getMinLength());
assertEquals(Integer.MAX_VALUE, field.getMaxLength());
assertEquals(false, field.isLeftAligned());
}
/**
* Check constructor
*
*/
public void testConstructor() {
FormattingInfo field = new FormattingInfo(true, 3, 6);
assertNotNull(field);
assertEquals(3, field.getMinLength());
assertEquals(6, field.getMaxLength());
assertEquals(true, field.isLeftAligned());
}
/**
* Field exceeds maximum width
*/
public void testTruncate() {
StringBuffer buf = new StringBuffer("foobar");
FormattingInfo field = new FormattingInfo(true, 0, 3);
field.format(2, buf);
assertEquals("fobar", buf.toString());
}
/**
* Add padding to left since field is not minimum width.
*/
public void testPadLeft() {
StringBuffer buf = new StringBuffer("foobar");
FormattingInfo field = new FormattingInfo(false, 5, 10);
field.format(2, buf);
assertEquals("fo obar", buf.toString());
}
/**
* Add padding to right since field is not minimum width.
*/
public void testPadRight() {
StringBuffer buf = new StringBuffer("foobar");
FormattingInfo field = new FormattingInfo(true, 5, 10);
field.format(2, buf);
assertEquals("foobar ", buf.toString());
}
}
1.6 +4 -3 logging-log4j/tests/src/java/org/apache/log4j/rolling/FilterBasedRollingTest.java
Index: FilterBasedRollingTest.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/rolling/FilterBasedRollingTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FilterBasedRollingTest.java 26 May 2005 06:05:38 -0000 1.5
+++ FilterBasedRollingTest.java 2 Jun 2005 05:48:57 -0000 1.6
@@ -48,7 +48,7 @@
}
public void tearDown() {
- LogManager.shutdown();
+ LogManager.getLoggerRepository().resetConfiguration();
}
/**
@@ -67,7 +67,7 @@
* Test basic rolling functionality using explicit configuration.
* Test fails when run immediately after test1.
*/
- public void xtest2() throws Exception {
+ public void test2() throws Exception {
PatternLayout layout = new PatternLayout("%m\n");
RollingFileAppender rfa = new RollingFileAppender();
rfa.setName("ROLLING");
@@ -82,7 +82,8 @@
fbtp.activateOptions();
swrp.setMinIndex(0);
- swrp.setActiveFileName("output/filterBased-test2.log");
+ rfa.setFile("output/filterBased-test2.log");
+ rfa.setAppend(false);
swrp.setFileNamePattern("output/filterBased-test2.%i");
swrp.activateOptions();
1.6 +1 -4 logging-log4j/tests/src/java/org/apache/log4j/rolling/helper/FileNamePatternTestCase.java
Index: FileNamePatternTestCase.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/rolling/helper/FileNamePatternTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileNamePatternTestCase.java 25 May 2005 05:33:15 -0000 1.5
+++ FileNamePatternTestCase.java 2 Jun 2005 05:48:57 -0000 1.6
@@ -42,15 +42,12 @@
private static class FileNameTestRollingPolicy extends RollingPolicyBase {
public FileNameTestRollingPolicy(final String pattern) {
- fileNamePatternStr = pattern;
+ setFileNamePattern(pattern);
parseFileNamePattern();
}
public void activateOptions() {
}
- public String getActiveFileName() {
- return null;
- }
public RolloverDescription initialize(final String activeName, final boolean append) {
return null;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org