Permalink
Browse files

fixed #286 CsvReporter does not reliably close csv files/streams

All PrintStream.close() calls are wrapped in a try/catch with
exceptions being logged
  • Loading branch information...
1 parent 10ccc80 commit 18643841383ee4f53357271319f7d20a00e33945 @jetztgradnet committed Sep 29, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 metrics-core/src/main/java/com/yammer/metrics/reporting/CsvReporter.java
@@ -4,6 +4,8 @@
import com.yammer.metrics.core.*;
import com.yammer.metrics.stats.Snapshot;
import com.yammer.metrics.core.MetricPredicate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
@@ -22,6 +24,8 @@
public class CsvReporter extends AbstractPollingReporter implements
MetricProcessor<CsvReporter.Context> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CsvReporter.class);
+
/**
* Enables the CSV reporter for the default metrics registry, and causes it to write to files in
* {@code outputDir} with the specified period.
@@ -244,7 +248,11 @@ public void shutdown() {
super.shutdown();
} finally {
for (PrintStream out : streamMap.values()) {
- out.close();
+ try {
+ out.close();
+ } catch (Throwable t) {
+ LOGGER.warn("Failed to close stream", t);
+ }
}
}
}

0 comments on commit 1864384

Please sign in to comment.