1

我的 java.util.logging.FileHandler.limit 属性有问题,因为文件大小超过了限制大小这里是我的应用程序中使用的属性

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

它工作正常,然后在某些时候应用程序只写入一个文件,没有超过配置文件大小的限制,大约 1 GB,要恢复正常配置,我必须重新启动我的应用程序。

操作系统是windows server 2012 java 7

有没有人有类似的问题?这可能在高负载下发生吗?

提前致谢

4

1 回答 1

0

某些东西正在重置您的 LogManager 属性,或者您正在运行java.util.logging.FileHandler 整数溢出防止文件轮换。尝试安装以下格式化程序,查看防止旋转的条件。

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());
    }
}

然后搜索您的日志文件以查看是否找到任何内容。

更新: Oracle 正在JDK-8059767 下解决此问题 FileHandler 应该允许“长”限制并处理 MeteredStream.written 的溢出。

于 2014-09-08T14:12:01.290 回答