commit | 8a6b9ca51d17f2bf2aafe15a8448ce28977c415b | [log] [tgz] |
---|---|---|
author | Michael Blow <mblow@apache.org> | Wed Jul 27 19:40:33 2016 -0400 |
committer | Michael Blow <mblow@apache.org> | Wed Jul 27 17:50:29 2016 -0700 |
tree | cd5dc39b8b87ce7a4d823923ddc7e9565c582a3e | |
parent | 70908dfb463f70a7d50dcb94cfc14defd76fa720 [diff] |
ASTERIXDB-1553: ClusterControllerService Dir/File Creation On-Demand Change-Id: Ie2e65cf083b3eb2db3e716f2b34fb28fe01debca Reviewed-on: https://asterix-gerrit.ics.uci.edu/1029 Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu> Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/logs/LogFile.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/logs/LogFile.java index 7eb0674..8f95c35 100644 --- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/logs/LogFile.java +++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/logs/LogFile.java
@@ -27,6 +27,7 @@ public class LogFile { private final File root; + private long openTime; private PrintWriter out; public LogFile(File root) { @@ -34,18 +35,23 @@ } public void open() throws Exception { - root.mkdirs(); - out = new PrintWriter(new FileOutputStream(new File(root, String.valueOf(System.currentTimeMillis()) + ".log"), - true)); + openTime = System.currentTimeMillis(); } - public void log(JSONObject object) throws Exception { + public synchronized void log(JSONObject object) throws Exception { + if (out == null) { + root.mkdirs(); + out = new PrintWriter(new FileOutputStream(new File(root, openTime + ".log"), true)); + } out.println(object.toString(1)); out.flush(); } - public void close() { - out.flush(); - out.close(); + public synchronized void close() { + if (out != null) { + out.flush(); + out.close(); + out = null; + } } }