1

I have problem with java.util.logging.FileHandler.limit property as file size exceeded the limit size here are used properties in my application

java.util.logging.FileHandler.pattern = ATMChannelAdapter%u.log
java.util.logging.FileHandler.limit = 2000000
java.util.logging.FileHandler.count = 10
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

it works fine and then at some point application writes in only one file with no limit beyond the configuration file size riches 1 GB approximately and to back to normal configuration I have to restart my application.

operating system is windows server 2012 java 7

does anyone have similar issue? is this could be happened in high load?

Thanks in advance

  • Is your posted config the whole configuration? I am missing a line like `handlers = java.util.logging.FileHandler` – Korashen Sep 08 '14 at 08:49
  • there are more configuration properties handlers= java.util.logging.ConsoleHandler ,java.util.logging.FileHandler .level= INFO 'java.util.logging.ConsoleHandler.level = INFO java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter' – user1996632 Sep 08 '14 at 09:32
  • I also noticed that count and size working will in first roll, then when the 10th file reached limit no more rolling and continue writing to last file in order – user1996632 Sep 08 '14 at 09:36
  • The configuration looks OK, it should work as expected. Have you tried to instanciate and configure a FileHandler via code? `FileHandler(String pattern, int limit, int count)`. Can you try this one out? If the configuration via Code works, I guess some kind of problems with reading the config file itself. – Korashen Sep 08 '14 at 10:40
  • Thank you for your reply, I am already using this constructor and I am facing this issue, I thought this related to JDK 7 – user1996632 Sep 08 '14 at 11:16
  • java -Djava.util.logging.config.file=channel_adapter_logging.properties -jar app.jar – user1996632 Sep 08 '14 at 12:07

1 Answers1

0

Something is resetting your LogManager properties or you are running in to java.util.logging.FileHandler integer overflow prevents file rotation. Try to install the following formatter which looks at the conditions that prevent rotation.

public class FileSimpleFormatter extends SimpleFormatter {

    private static final Field METER;
    private static final Field COUNT;

    static {
        try {
            METER = FileHandler.class.getDeclaredField("meter");
            METER.setAccessible(true);

            COUNT = FileHandler.class.getDeclaredField("count");
            COUNT.setAccessible(true);
        } catch (RuntimeException re) {
            throw re;
        } catch (Exception e) {
            throw new ExceptionInInitializerError(e);
        }
    }

    private volatile FileHandler h;

    @Override
    public String getHead(Handler h) {
        this.h = FileHandler.class.cast(h);
        return super.getHead(h);
    }

    private String check() {
        FileHandler target = h;
        if (target != null) {
            try {
                Object os = METER.get(target);
                if (os != null && os.getClass().getName().endsWith("MeteredStream")) {
                    Field written = os.getClass().getDeclaredField("written");
                    written.setAccessible(true);
                    Number c = Number.class.cast(COUNT.get(target));
                    Number w = Number.class.cast(written.get(os));
                    if (c.intValue() <= 0 || w.intValue() < 0) {
                        return String.format("target=%1$s count=%2$s written=%3$s%n",
                                target, c, w);
                    }
                }
            } catch (IllegalAccessException ex) {
                throw (Error) new IllegalAccessError(ex.getMessage()).initCause(ex);
            } catch (NoSuchFieldException ex) {
                throw (Error) new NoSuchFieldError(ex.getMessage()).initCause(ex);
            }
        }
        return "";
    }

    @Override
    public String format(LogRecord record) {
        return super.format(record).concat(check());
    }
}

Then search your log file to see if it found anything.

Update: Oracle is working this issue under JDK-8059767 FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.

jmehrens
  • 10,580
  • 1
  • 38
  • 47