我遇到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
有没有人有类似的问题?这可能发生在高负荷吗?
提前致谢
答案 0 :(得分:0)
正在重置您的LogManager属性,或者您正在运行java.util.logging.FileHandler integer overflow prevents file 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());
}
}
然后搜索您的日志文件以查看它是否找到了任何内容。
更新:Oracle正在JDK-8059767 FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
下处理此问题