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 org.joda.time.MutableDateTime;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
@ -69,10 +70,7 @@ public class FileRequestLogger implements RequestLogger
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
currentDay = mutableDateTime.toDateTime();
|
currentDay = mutableDateTime.toDateTime();
|
||||||
|
|
||||||
fileWriter = new OutputStreamWriter(
|
fileWriter = getFileWriter();
|
||||||
new FileOutputStream(new File(baseDir, currentDay.toString("yyyy-MM-dd'.log'")), true),
|
|
||||||
Charsets.UTF_8
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
long nextDay = currentDay.plusDays(1).getMillis();
|
long nextDay = currentDay.plusDays(1).getMillis();
|
||||||
Duration delay = new Duration(nextDay - new DateTime().getMillis());
|
Duration delay = new Duration(nextDay - new DateTime().getMillis());
|
||||||
|
@ -90,10 +88,7 @@ public class FileRequestLogger implements RequestLogger
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
currentDay = currentDay.plusDays(1);
|
currentDay = currentDay.plusDays(1);
|
||||||
CloseQuietly.close(fileWriter);
|
CloseQuietly.close(fileWriter);
|
||||||
fileWriter = new OutputStreamWriter(
|
fileWriter = getFileWriter();
|
||||||
new FileOutputStream(new File(baseDir, currentDay.toString()), true),
|
|
||||||
Charsets.UTF_8
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
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
|
@LifecycleStop
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue