Menu ▾ ▴

#27 IOException closing 1st XML logfile

0.9.3.1
open
5
2002-01-15
2001-11-23
No

An IOException is thrown when closing the 1st logfile
(when multiple logfiles are generated), but only when
using the XMLFormatter. The exception is not thrown
when closing any of the other logfiles subsequently
used in the rotation.

This exception is not thrown when using the
SimpleFormatter.

/////////////////////////////////////////////

Platform: Windows 2000
JVM: 1.3.1

/////////////////////////////////////////////

// Sample code (modified from logger HelloWorld):

package net.sourceforge.javalogging;
import java.util.logging.*;

public class HelloWorld {

private static Logger theLogger = Logger.getLogger(
HelloWorld.class.getName() );
private static FileHandler fh;
private static final int LOG_MAX_SIZE = 500;
private static final int LOG_ROTATION_COUNT = 3;

public static void main( String[] args ) {

// create log file with formatting
try {
fh = new FileHandler("mylog.%u.%g.txt",
LOG_MAX_SIZE, LOG_ROTATION_COUNT);
} catch( Exception e) {}

// use XMLFormatter to reproduce IOException.
// use SimpleFormatter, and no exception is thrown.
// fh.setFormatter( new SimpleFormatter());
fh.setFormatter( new XMLFormatter());

theLogger.addHandler(fh);
theLogger.setLevel(Level.ALL);

HelloWorld hello = new HelloWorld( "Hello Adam!" );
hello.sayHello();
}

private String theMessage;

public HelloWorld( String message ) {
theMessage = message;
}

public void sayHello() {
while (true) {
theLogger.fine( theMessage );
}
}

}

/////////////////////////////////////////////

Exception Stack Trace:
java.io.IOException: Bad file descriptor
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write
(FileOutputStream.java:212)
at java.io.BufferedOutputStream.flushBuffer
(BufferedOutputStream.java:72)
at java.io.BufferedOutputStream.flush
(BufferedOutputStream.java:130)
at java.io.OutputStreamWriter.flush
(OutputStreamWriter.java:245)
at java.io.OutputStreamWriter.close
(OutputStreamWriter.java:258)
at java.util.logging.StreamHandler.close
(StreamHandler.java:148)
at java.util.logging.FileHandler.close
(FileHandler.java:108)
at java.util.logging.StreamHandler.setOutputStream
(StreamHandler.java:195)
at java.util.logging.FileHandler.switchFiles
(FileHandler.java:310)
at java.util.logging.FileHandler.publish
(FileHandler.java:117)
at java.util.logging.Logger.log(Logger.java:268)
at java.util.logging.Logger.log(Logger.java:216)
at java.util.logging.Logger.fine(Logger.java:160)
at net.sourceforge.javalogging.HelloWorld.sayHello
(HelloWorld.java)
at net.sourceforge.javalogging.HelloWorld.main
(HelloWorld.java)

/////////////////////////////////////////////

Harry Wolfson
hwolfson@outerlink.com
hwolfson@wolfpup.org

Discussion

  • Brian R. Gilstrap

    • labels: 336690 --> XMLFormatter
    • assigned_to: nobody --> gilstrap
     
  • Brian R. Gilstrap

    • milestone: --> 0.9.3.1
     

Log in to post a comment.