Log4jのBurstFilterは、ディスクをいっぱいにするのを防ぐのに役立ちます。可能な限りコードの一部として適用されるように設定するか、保持したいメッセージを除外します(つまり、アペンダ上では使用しませんが、特定のロガーに対しては使用しないでください)。あなたのコードで分離する)。
ロガーをラップし、指定された期間内にn個のメッセージに基づいてフィルタリングされたシンプルなユーティリティクラスを作成しました。私は、あなたのような問題に遭遇する機会を守るために、私の警告とエラーログの大部分でそのインスタンスを使用しました。私の状況では、さまざまな状況に迅速に適応することが容易だったため、これはかなりうまく機能しました。
何かのように:
...
public DurationThrottledLogger(Logger logger, Duration throttleDuration, int maxMessagesInPeriod) {
...
}
public void info(String msg) {
getMsgAddendumIfNotThrottled().ifPresent(addendum->logger.info(msg + addendum));
}
private synchronized Optional<String> getMsgAddendumIfNotThrottled() {
LocalDateTime now = LocalDateTime.now();
String msgAddendum;
if (throttleDuration.compareTo(Duration.between(lastInvocationTime, now)) <= 0) {
// last one was sent longer than throttleDuration ago - send it and reset everything
if (throttledInDurationCount == 0) {
msgAddendum = " [will throttle future msgs within throttle period]";
} else {
msgAddendum = String.format(" [previously throttled %d msgs received before %s]",
throttledInDurationCount, lastInvocationTime.plus(throttleDuration).format(formatter));
}
totalMessageCount++;
throttledInDurationCount = 0;
numMessagesSentInCurrentPeriod = 1;
lastInvocationTime = now;
return Optional.of(msgAddendum);
} else if (numMessagesSentInCurrentPeriod < maxMessagesInPeriod) {
msgAddendum = String.format(" [message %d of %d within throttle period]", numMessagesSentInCurrentPeriod + 1, maxMessagesInPeriod);
// within throttle period, but haven't sent max messages yet - send it
totalMessageCount++;
numMessagesSentInCurrentPeriod++;
return Optional.of(msgAddendum);
} else {
// throttle it
totalMessageCount++;
throttledInDurationCount++;
return emptyOptional;
}
}
私は残念ながら、コードの古いバージョンからこれを引っ張ってんだけど、要点があります。彼らは私がその1つのログメッセージのためにこれらのいずれかを作成するためのコードを一行も書いてみましょうので、私は私が主に使用される静的ファクトリメソッドの束を書いた:
} catch (IOException e) {
DurationThrottledLogger.error(logger, Duration.ofSeconds(1), "Received IO Exception. Exiting current reader loop iteration.", e);
}
これはおそらく、あなたのように重要ではありません場合;私たちのために、我々は非常に簡単に泳ぐことができる幾分弱い卒業論文を使用していました。
ログファイルのサイズや数量を拡大しようとしましたか?また、問題の実際の解決策は、すべてのスタックトレースを引き起こしていることを修正するように見えます。 – DwB
@DwB、私は元々の質問で述べたように、私はVMディスクのサイズ(多くの場合、私の手にはない決定、別々に対処されている)を支配していません。スタックトレースの原因を修正するためのあなたの提案の他の部分に:もちろん、それは与えられたものですが、私たちは理想的な世界に住んでいません。特に、システムに統合ポイントと依存関係があり、私のコントロール外に下がってしまったときに、私はすべてのことを修正したいとは思っていません。また、私が言ったように - ポイントは予期しないエラー出力があるときにログを保持することです。 –