You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2001/02/20 20:17:11 UTC
cvs commit: jakarta-log4j/org/apache/log4j/test UnitTestDRFA.java Makefile
ceki 01/02/20 11:17:10
Modified: build build.xml
org/apache/log4j FileAppender.java Makefile
RollingFileAppender.java WriterAppender.java
org/apache/log4j/test Makefile
Added: build manifest.mf
org/apache/log4j DailyRollingFileAppender.java
org/apache/log4j/test UnitTestDRFA.java
Removed: . manifest.mf
Log:
The manifest file is now created through ANT filtering.
Added org/apache/log4j/DailyRollingFileAppender.java
Revision Changes Path
1.9 +18 -15 jakarta-log4j/build/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-log4j/build/build.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- build.xml 2001/02/14 22:41:38 1.8
+++ build.xml 2001/02/20 19:16:41 1.9
@@ -20,7 +20,7 @@
ant jar - build log4j-core and log4j jar files
- ant distrib - will make a distribution in ../../dump/
+ ant distrib - will create a distribution in ../../dump/
</echo>
</target>
@@ -82,11 +82,9 @@
<echo message="JAVAMAIL is present."/>
</target>
-
-
<!-- ================================================================= -->
<!-- Initialize variables -->
- <!-- NOTE: all directories are relative to ../build -->
+ <!-- NOTE: all directories are relative to ../build/ -->
<!-- ================================================================= -->
<target name="init">
<tstamp />
@@ -124,7 +122,7 @@
<target name="build.swing" depends="init, swing" if="swing-present">
<mkdir dir="${javac.dest}/icons"/>
- <copy todir="${javac.dest}/icons">
+ <copy todir="${javac.dest}/icons" >
<fileset dir="icons"/>
</copy>
<javac srcdir="${java.source.dir}"
@@ -139,7 +137,7 @@
destdir="${javac.dest}"
includes="**/UnitTest*.java"
classpath="${classpath}"/>
-</target>
+ </target>
<target name="build.xml" depends="init, xerces, sunParser" if="jaxp-present">
<javac srcdir="${java.source.dir}"
@@ -150,7 +148,7 @@
classpath="${classpath}"/>
<copy file="${stem}/xml/log4j.dtd"
tofile="${javac.dest}/${stem}/xml/log4j.dtd" />
-</target>
+ </target>
<target name="build.javamail" depends="init, javamail"
if="javamail-present">
@@ -175,9 +173,15 @@
<target name="jar" depends="log4j-core.jar, log4j.jar"/>
+ <target name="prejar" depends="build">
+ <mkdir dir="${jar.dest}"/>
+ <filter token="version" value="${version}" />
+ <copy file="build/manifest.mf" tofile="lib/manifest.mf" filtering="true"/>
+ </target>
+
+
<!-- Create log4j-core.jar, exluding non-core files -->
- <target name="log4j-core.jar" depends="build">
- <mkdir dir="${jar.dest}"/>
+ <target name="log4j-core.jar" depends="prejar">
<delete file="${jar.dest}/log4j-core.jar"/>
<jar jarfile="${jar.dest}/log4j-core.jar" basedir="${javac.dest}"
includes="**/log4j/*.class, **/log4j/helpers/*.class,
@@ -190,14 +194,13 @@
${stem}/or/MessageRenderer.class,
${stem}/spi/TriggeringEventEvaluator.class
org/apache/log4j/helpers/CyclicBuffer.class"
- manifest="manifest.mf"
+ manifest="lib/manifest.mf"
/>
</target>
<!-- Create log4j.jar, excluding tests and other odds and
ends. -->
- <target name="log4j.jar" depends="build">
- <mkdir dir="${jar.dest}"/>
+ <target name="log4j.jar" depends="prejar">
<delete file="${jar.dest}/log4j.jar"/>
<jar jarfile="${jar.dest}/log4j.jar" basedir="${javac.dest}"
includes="**/log4j/*.class, ${stem}/xml/log4j.dtd,
@@ -208,7 +211,7 @@
**/log4j/or/*.class,
**/log4j/gui/TextPaneAppender.class"
excludes="**/StressCategory*, **/UnitTest**"
- manifest="manifest.mf"
+ manifest="lib/manifest.mf"
/>
</target>
@@ -220,7 +223,7 @@
<mkdir dir="${javadoc.dest}" />
- <copy todir="${stem}/examples/doc-files/" >
+ <copy todir="${stem}/examples/doc-files/">
<fileset dir="${stem}/examples/"
includes="Sort.java, SortAlgo.java, Trivial.java, MyCategory.java,
MyCategoryFactory.java, mycat.good, mycat.bad, factor.html,
@@ -235,7 +238,7 @@
extension2.xml, XCategory.java,XTest.java"/>
</copy>
- <copy todir="${stem}/xml/doc-files/" >
+ <copy todir="${stem}/xml/doc-files/" >
<fileset dir="${stem}/xml/" includes="log4j.dtd"/>
</copy>
1.1 jakarta-log4j/build/manifest.mf
Index: manifest.mf
===================================================================
Manifest-version: 1.0
Name: org/apache/log4j/
Implementation-Title: log4j
Implementation-Version: @version@
Implementation-Vendor: "Apache Softwate Foundation"
1.12 +3 -0 jakarta-log4j/org/apache/log4j/FileAppender.java
Index: FileAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/FileAppender.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FileAppender.java 2001/02/20 08:05:12 1.11
+++ FileAppender.java 2001/02/20 19:16:50 1.12
@@ -160,6 +160,8 @@
errorHandler.error("setFile("+fileName+","+fileAppend+") call failed.",
e, ErrorCode.FILE_OPEN_FAILURE);
}
+ } else {
+ LogLog.error("Filename option not set for appender ["+name+"].");
}
}
@@ -171,6 +173,7 @@
// FIXME (remove qwIsOurs)
if(this.qw != null && this.qwIsOurs) {
try {
+ LogLog.debug("////////////////////////////////////////////////");
this.qw.close();
}
catch(java.io.IOException e) {
1.5 +1 -1 jakarta-log4j/org/apache/log4j/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Makefile 2001/02/13 17:37:06 1.4
+++ Makefile 2001/02/20 19:16:52 1.5
@@ -2,6 +2,7 @@
PKG_DIR :=org/apache/log4j
DEPTH :=../../..
JSOURCES:=HTMLLayout.java\
+ DailyRollingFileAppender.java\
RollingFileAppender.java\
PropertyConfigurator.java\
PatternLayout.java\
@@ -24,7 +25,6 @@
ConsoleAppender.java\
SUBDIRS :=helpers spi or xml net nt varia test performance examples gui
-
# include master-rule file
include $(DEPTH)/make/make.inc
1.4 +4 -4 jakarta-log4j/org/apache/log4j/RollingFileAppender.java
Index: RollingFileAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/RollingFileAppender.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RollingFileAppender.java 2001/02/13 17:37:07 1.3
+++ RollingFileAppender.java 2001/02/20 19:16:54 1.4
@@ -17,6 +17,7 @@
import java.io.OutputStreamWriter;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.helpers.QuietWriter;
+import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.helpers.CountingQuietWriter;
import org.apache.log4j.spi.LoggingEvent;
@@ -123,8 +124,8 @@
<code>File</code> is truncated with no backup files created.
*/
- public
- synchronized
+
+ public // synchronization not necessary since doAppend is alreasy synched
void rollOver() {
File target;
File file;
@@ -160,8 +161,7 @@
this.setFile(fileName, false);
}
catch(IOException e) {
- System.err.println("setFile("+fileName+", false) call failed.");
- e.printStackTrace();
+ LogLog.error("setFile("+fileName+", false) call failed.", e);
}
}
1.4 +3 -3 jakarta-log4j/org/apache/log4j/WriterAppender.java
Index: WriterAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/WriterAppender.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WriterAppender.java 2001/02/20 08:05:12 1.3
+++ WriterAppender.java 2001/02/20 19:16:56 1.4
@@ -149,13 +149,13 @@
}
if(this.qw == null) {
- errorHandler.error("No output target set for appender named \""+
- name+"\".");
+ errorHandler.error("No output stream or file set for appender named ["+
+ name+"].");
return false;
}
if(this.layout == null) {
- errorHandler.error("No layout set for appender named \""+ name+"\".");
+ errorHandler.error("No layout set for appender named ["+ name+"].");
return false;
}
return true;
1.1 jakarta-log4j/org/apache/log4j/DailyRollingFileAppender.java
Index: DailyRollingFileAppender.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.APL file. */
package org.apache.log4j;
import java.io.IOException;
import java.io.Writer;
import java.io.FileWriter;
import java.io.File;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Calendar;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.helpers.QuietWriter;
import org.apache.log4j.helpers.CountingQuietWriter;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ErrorCode;
/**
DailyRollingFileAppender extends FileAppender to use filenames formatted
with date/time information. The filename is recomputed every day at
midnight. Note that the filename doesn't have to change every day,
making it possible to have logfiles which are per-week or
per-month.
The appender computes the proper filename using the formats
specified in {@link SimpleDateFormat.html}. The format requires
that most static text is enclosed in single quotes, which are
removed. The examples below show how quotes are used to embed
static information in the format.
Sample filenames:
<code>
Filename pattern Filename
"'/logs/trace-'yyyy-MM-dd'.log'" /logs/trace-2000-12-31.log
"'/logs/trace-'yyyy-ww'.log'" /logs/trace-2000-52.log
</code>
@author <a HREF="mailto:eirik.lygre@evita.no">Eirik Lygre</a> */
public class DailyRollingFileAppender extends FileAppender {
// The code assumes that the following constants are in a increasing
// sequence.
static final int TOP_OF_ZONK =-1;
static final int TOP_OF_MINUTE = 0;
static final int TOP_OF_HOUR = 1;
static final int HALF_DAY = 2;
static final int TOP_OF_DAY = 3;
static final int TOP_OF_WEEK = 4;
static final int TOP_OF_MONTH = 5;
/**
A string constant used in naming the option for setting the
filename pattern. Current value of this string constant is
<strong>datePattern</strong>.
*/
static final public String DATE_PATTERN_OPTION = "DatePattern";
/**
The date pattern. By default, the rolled file extension is
the date folloed by .log. The rollover occurs at midnight. '
*/
private String datePattern = ".YYYY-MM-dd.log";
/**
The actual formatted filename that is currently being written to
*/
private String lastDatedFilename;
/**
The timestamp when we shall next recompute the filename
*/
private long nextCheck = System.currentTimeMillis () - 1;
Date now = new Date();
SimpleDateFormat sdf;
RollingCalendar rc = new RollingCalendar();
int checkPeriod = TOP_OF_ZONK;
/**
The default constructor does nothing. */
public
DailyRollingFileAppender() {
}
/**
Instantiate a <code>DailyRollingFileAppender</code> and open the
file designated by <code>filename</code>. The opened filename will
become the ouput destination for this appender.
*/
public DailyRollingFileAppender (Layout layout, String filename,
String datePattern) throws IOException {
super(layout, filename, true);
this.datePattern = datePattern;
sdf = new SimpleDateFormat(datePattern);
int type = computeCheckPeriod();
printPeriodicity(type);
rc.setType(type);
}
public
void activateOptions() {
super.activateOptions();
if(datePattern != null && fileName != null) {
lastDatedFilename = fileName+sdf.format(now);
} else {
LogLog.error("Either Filename or DatePattern options are not set for ["+
name+"].");
}
}
void printPeriodicity(int type) {
switch(type) {
case TOP_OF_MINUTE:
LogLog.debug("Appender ["+name+"] to be rolled every minute.");
break;
case TOP_OF_HOUR:
LogLog.debug("Appender ["+name
+"] to be rolled on top of every hour.");
break;
case HALF_DAY:
LogLog.debug("Appender ["+name
+"] to be rolled at midday and midnight.");
break;
case TOP_OF_DAY:
LogLog.debug("Appender ["+name
+"] to be rolled at midnight.");
break;
case TOP_OF_WEEK:
LogLog.debug("Appender ["+name
+"] to be rolled at start of week.");
break;
case TOP_OF_MONTH:
LogLog.debug("Appender ["+name
+"] to be rolled at start of every month.");
break;
default:
LogLog.warn("Unknown periodicity for appender ["+name+"].");
}
}
int computeCheckPeriod() {
RollingCalendar c = new RollingCalendar();
// set sate to 1970-01-01 00:00:00 GMT
Date epoch = new Date(0);
if(datePattern != null) {
System.err.println("DatePattern = "+datePattern);
for(int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) {
String r0 = sdf.format(epoch);
c.setType(i);
Date next = new Date(c.getNextCheckTime(epoch));
String r1 = sdf.format(next);
if(r0 != null && r1 != null && !r0.equals(r1)) {
return i;
}
}
}
// Deliberately head for trouble...
return TOP_OF_ZONK;
}
/**
Set the current output file.
The function will compute a new filename, and open a new file only
when the name has changed.
The function is automatically called once a day, to allow for
daily rolling files -- the purpose of this class. */
public
synchronized
void rollOver() throws IOException {
LogLog.debug("RollOver called-------------------------");
/* Compute filename, but only if datePattern is specified */
if (datePattern == null) {
errorHandler.error("Missing "+DATE_PATTERN_OPTION+
" option in rollOver().");
return;
}
String datedFilename = fileName+sdf.format(now);
if (lastDatedFilename.equals(datedFilename)) {
LogLog.debug(lastDatedFilename+"="+datedFilename+"==================");
return;
}
LogLog.debug("NexCheck="+nextCheck);
LogLog.debug("Target = "+datedFilename);
// close current file, and rename it to datedFilename
this.closeFile();
File target = new File(lastDatedFilename);
if (target.exists()) {
target.delete();
}
File file = new File(fileName);
file.renameTo(target);
LogLog.debug(fileName +" -> "+ lastDatedFilename);
try {
// This will also close the file. This is OK since multiple
// close operations are safe.
this.setFile(fileName, false);
}
catch(IOException e) {
LogLog.error("setFile("+fileName+", false) call failed., e");
}
lastDatedFilename = datedFilename;
}
/**
This method differentiates DailyRollingFileAppender from its
super class.
*/
protected
void subAppend(LoggingEvent event) {
long n = System.currentTimeMillis();
if (n >= nextCheck) {
now.setTime(n);
nextCheck = rc.getNextCheckTime(now);
try {
rollOver();
} catch(IOException e) {
LogLog.error("setFile(null, false) call failed.", e);
}
}
super.subAppend(event);
}
/**
Retuns the option names for this component, namely {@link
#FILE_NAME_PATTERN_OPTION} in
addition to the options of {@link FileAppender#getOptionStrings
FileAppender}.
*/
public
String[] getOptionStrings() {
return OptionConverter.concatanateArrays(super.getOptionStrings(),
new String[] {DATE_PATTERN_OPTION});
}
/**
Set the options for the appender
*/
public
void setOption(String key, String value) {
super.setOption(key, value);
if(key.equalsIgnoreCase(DATE_PATTERN_OPTION)) {
datePattern = value;
now.setTime(System.currentTimeMillis());
sdf = new SimpleDateFormat(datePattern);
int type = computeCheckPeriod();
printPeriodicity(type);
rc.setType(type);
}
}
/**
RollingCalendar is a helper class to
DailyRollingFileAppender. Using this class, it is easy to compute
and access the next Millis()
It subclasses the standard {@link GregorianCalendar}-object, to
allow access to the protected function getTimeInMillis(), which it
then exports.
@author <a HREF="mailto:eirik.lygre@evita.no">Eirik Lygre</a> */
class RollingCalendar extends GregorianCalendar {
int type;
void setType(int type) {
this.type = type;
LogLog.debug("Type = "+type);
}
public
long getNextCheckTime(Date now) {
this.setTime(now);
switch(type) {
case TOP_OF_MINUTE:
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
this.add(Calendar.MINUTE, +1);
break;
case TOP_OF_HOUR:
this.set(Calendar.MINUTE, 0);
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
this.add(Calendar.HOUR, +1);
break;
case HALF_DAY:
this.set(Calendar.MINUTE, 0);
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
this.add(Calendar.HOUR, (get(Calendar.HOUR_OF_DAY)/12)*12);
break;
case TOP_OF_DAY:
this.set(Calendar.HOUR, 0);
this.set(Calendar.MINUTE, 0);
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
this.add(Calendar.DAY_OF_MONTH, +1);
break;
case TOP_OF_WEEK:
this.set(Calendar.DAY_OF_WEEK, getFirstDayOfWeek());
this.set(Calendar.HOUR, 0);
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
this.add(Calendar.WEEK_OF_YEAR, 1);
break;
case TOP_OF_MONTH:
this.set(Calendar.DATE, 1);
this.set(Calendar.HOUR, 0);
this.set(Calendar.SECOND, 0);
this.set(Calendar.MILLISECOND, 0);
this.add(Calendar.MONTH, +1);
break;
default:
throw new IllegalStateException("Unknown periodicity type.");
}
return super.getTimeInMillis();
}
}
}
1.8 +1 -1 jakarta-log4j/org/apache/log4j/test/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/test/Makefile,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Makefile 2001/02/13 17:37:29 1.7
+++ Makefile 2001/02/20 19:17:05 1.8
@@ -24,8 +24,8 @@
UnitTestBoundedFIFO.java\
UnitTestVarSubst.java\
SocketAppenderTest.java\
- UnitTestOR.java\
PrintProperties.java\
+ UnitTestOR.java\
SUBDIRS :=
1.1 jakarta-log4j/org/apache/log4j/test/UnitTestDRFA.java
Index: UnitTestDRFA.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.APL file. */
package org.apache.log4j;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.TestFailure;
import junit.framework.Test;
public class UnitTestDRFA extends TestCase {
public UnitTestDRFA(String name) {
super(name);
}
public
void test1() {
DailyRollingFileAppender drfa = new DailyRollingFileAppender();
drfa.setOption(DailyRollingFileAppender.DATE_PATTERN_OPTION,
"YY-MM-dd");
assertEquals(drfa.computeCheckPeriod(),
DailyRollingFileAppender.TOP_OF_DAY);
}
public
static
Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new UnitTestDRFA("test1"));
return suite;
}
}