Skip to content

Commit

Permalink
Fix rolling of request log files. (apache#3916)
Browse files Browse the repository at this point in the history
* Use common date format for request log files.

* Remove code duplication in creating logging FileWriter.
  • Loading branch information
jkukul authored and fjy committed Feb 14, 2017
1 parent af67e89 commit 28d8570
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions server/src/main/java/io/druid/server/log/FileRequestLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.joda.time.MutableDateTime;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -69,10 +70,7 @@ public void start()
synchronized (lock) {
currentDay = mutableDateTime.toDateTime();

fileWriter = new OutputStreamWriter(
new FileOutputStream(new File(baseDir, currentDay.toString("yyyy-MM-dd'.log'")), true),
Charsets.UTF_8
);
fileWriter = getFileWriter();
}
long nextDay = currentDay.plusDays(1).getMillis();
Duration delay = new Duration(nextDay - new DateTime().getMillis());
Expand All @@ -90,10 +88,7 @@ public ScheduledExecutors.Signal call()
synchronized (lock) {
currentDay = currentDay.plusDays(1);
CloseQuietly.close(fileWriter);
fileWriter = new OutputStreamWriter(
new FileOutputStream(new File(baseDir, currentDay.toString()), true),
Charsets.UTF_8
);
fileWriter = getFileWriter();
}
}
catch (Exception e) {
Expand All @@ -110,6 +105,13 @@ public ScheduledExecutors.Signal call()
}
}

private OutputStreamWriter getFileWriter() throws FileNotFoundException {
return new OutputStreamWriter(
new FileOutputStream(new File(baseDir, currentDay.toString("yyyy-MM-dd'.log'")), true),
Charsets.UTF_8
);
}

@LifecycleStop
public void stop()
{
Expand Down

0 comments on commit 28d8570

Please sign in to comment.