Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4362603

LOGGING APIs: redundant file is created when property pattern is set

XMLWordPrintable

    • sparc
    • solaris_7

      Name: szR10032 Date: 08/15/2000



      The testbase_nsk/src/nsk/logging/FileHandler/close/close001
      test shows that logging APIs implementation creates the redundant file
      (close001.0.log) when the constructor FileHandler(String name) is used by test. close001.0.log is only created
      if test runs with properties file
      (-Djava.util.logging.config.file=./logging.properties) containing
      java.util.logging.FileHandler.pattern
      (java.util.logging.FileHandler.pattern = close001.%g.log).
      The global handlers are not used by test at all.

      See log, property file and source below.

      LOG:
      ====
      novo7% /export/ld24/java/hotspot/Solaris_JDK_1.3/bin/javac -d . close001.java
      novo7% /export/ld24/java/hotspot/Solaris_JDK_1.3/bin/java -Xbootclasspath/a:/export/home/_FOR_REMOVING/logging/classes -Djava.util.logging.config.file=./logging.properties logging.FileHandler.close.close001
      FAILURE: (3) Superfluous file, created by logging APIs, are found: close001.0.log
      novo7%

      SOURCE:
      =======
      package logging.FileHandler.close;

      import java.util.logging.LogManager;
      import java.util.logging.FileHandler;
      import java.util.logging.Logger;
      import java.util.logging.Level;
      //import java.util.logging.SimpleFormatter;
      import java.util.logging.Formatter;
      import java.util.logging.LogRecord;
      import java.util.logging.Handler;

      import java.io.PrintStream;
      import java.io.FileInputStream;
      import java.io.InputStream;
      import java.io.DataInputStream;
      import java.io.File;

      public class close001 {
          static final String fname = "close001F";
          static int res = 0;
          static LogManager manager;
          static FileHandler fh;
          static Logger lggr;
          static PrintStream sout = null;
          static String str1 = null;
          static String str2 = null;

          public static void main( String argv[] ) {
              System.exit(run(argv, System.out)+95); // JCK-compatible exit status
          }
          
          public static int run(String argv[],PrintStream out) {
              sout = out;
              close001 test = new close001();

              try {
                  test.initit();
                  test.doit();
                  res = test.checkit();
              } catch (SecurityException ex) {
                  // If security manager exists and
                  // 1. access to pattern file is forbidden and/or
                  // 2. lAPIs methods callers do not have LoggingPermission("control")
                  out.println(ex);
                  return 0; //TEST PASSED
              } catch (Exception ex) {
                  out.println(ex);
                  return 2; //TEST FAILED
              }

              if (res == 1) {
                  return 0; //TEST PASSED
              }

              return 2; //TEST FAILED
          }

          private void doit() throws Exception {
              for (int i=0;i<10;i++) {
                  lggr.finest(str1);
                  fh.flush();
              }

              fh.close();
          }

          private int checkit() throws Exception {
              try {
                  for (int i=0;i<10;i++) {
                      lggr.finest(str2);
                      fh.flush();
                  }
                  fh.close();
              } catch (Exception ex) {
                  sout.println(ex);
                  return 0;
              }

              FileInputStream fis = new FileInputStream(fname);
              DataInputStream dis = new DataInputStream((InputStream) fis);
              String ln = null;
              int count = 0;

              for (;;) {
                  ln = dis.readLine();

                  if (ln == null) {
                      break;
                  }

                  if (ln.indexOf("=") != -1) {
                      count = 1;
                  }

                  if (ln.length() != 2300) {
                      count = 0;
                      sout.println("FAILURE: (1) the length of log file does not coincide with the demanded length.");
                      break;
                  }

                  if (ln.indexOf("#") != -1) {
                      count = 0;
                      sout.println("FAILURE: (2) log file is overwritten after the closing.");
                      break;
                  }
              }

              fis.close();


              File cd = new File(".");
              String flst[] = cd.list();
              int lc = flst.length;
              String cf = null;

              for (int j=0;j < lc;j++) {
                  cf = flst[j];

                  if (cf.compareTo("close001F") != 0 && cf.compareTo("logging.properties") != 0 && cf.compareTo("close001.java") != 0 && cf.compareTo("logging") != 0 && cf.compareTo("close001.cfg") != 0 && cf.compareTo("close001.README") != 0) {
                      count = 0;
                      sout.println("FAILURE: (3) Superfluous file, created by logging APIs, are found: "+cf);
                  }
              }

              return count;
          }

          private void initit() throws Exception {
              File f = new File(fname);
              f.delete();

              manager = LogManager.getLogManager();
              manager.removeAllGlobalHandlers();

              fh = new FileHandler(fname);
              fh.setFormatter(new close001f());
              fh.setLevel(Level.FINEST);

              lggr = Logger.getLogger("logging.FileHandler.close.close001.one");
              lggr.addHandler(fh);
              lggr.setLevel(Level.FINEST);
          }

          static {
              str1 = "==============================================" +
                     "==============================================" +
                     "==============================================" +
                     "==============================================" +
                     "==============================================" ;
          }

          static {
              str2 = "##############################################" +
                     "##############################################" +
                     "##############################################" +
                     "##############################################" +
                     "##############################################" ;
          }
      }


      class close001f extends Formatter {
          public java.lang.String format(LogRecord record) {
              return record.message; // returns only raw log message
          }
      }



      logging.properties:
      ===================
      handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
      .level= INFO
      java.util.logging.FileHandler.pattern = close001.%g.log
      java.util.logging.FileHandler.limit = 1000
      java.util.logging.FileHandler.count = 3
      java.util.logging.ConsoleHandler.level = INFO
      com.xyz.foo.level = SEVERE

      ======================================================================

            Unassigned Unassigned
            zsssunw Zss Zss (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: