mirror of https://github.com/apache/druid.git
Fix rolling of request log files. (#3916)
* Use common date format for request log files. * Remove code duplication in creating logging FileWriter.
This commit is contained in:
parent
af67e8904e
commit
28d85702ad
|
@ -32,6 +32,7 @@ import org.joda.time.Duration;
|
|||
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;
|
||||
|
@ -69,10 +70,7 @@ public class FileRequestLogger implements RequestLogger
|
|||
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());
|
||||
|
@ -90,10 +88,7 @@ public class FileRequestLogger implements RequestLogger
|
|||
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) {
|
||||
|
@ -110,6 +105,13 @@ public class FileRequestLogger implements RequestLogger
|
|||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue