aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper/Log.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-11-10 16:10:57 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-11-10 16:10:57 +1300
commitd1f6d1ab58e82c7854cb569554f7626be10f7baf (patch)
treef430345b55f3cdcdf074cf4ab90d01fea55fdcab /src/org/traccar/helper/Log.java
parent84b7b8c28d0a8a19fc1283dd4d3509c0295d8c3d (diff)
downloadtrackermap-server-d1f6d1ab58e82c7854cb569554f7626be10f7baf.tar.gz
trackermap-server-d1f6d1ab58e82c7854cb569554f7626be10f7baf.tar.bz2
trackermap-server-d1f6d1ab58e82c7854cb569554f7626be10f7baf.zip
Fix some FindBugs issues
Diffstat (limited to 'src/org/traccar/helper/Log.java')
-rw-r--r--src/org/traccar/helper/Log.java15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index a26da6b30..9519a33f1 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -19,11 +19,13 @@ import org.traccar.Config;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.ConsoleHandler;
@@ -59,11 +61,14 @@ public final class Log {
if (writer != null && !suffix.equals(this.suffix)) {
writer.close();
writer = null;
- new File(name).renameTo(new File(name + "." + this.suffix));
+ if (!new File(name).renameTo(new File(name + "." + this.suffix))) {
+ throw new RuntimeException("Log file renaiming failed");
+ }
}
if (writer == null) {
this.suffix = suffix;
- writer = new BufferedWriter(new FileWriter(name, true));
+ writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(name, true), StandardCharsets.UTF_8));
}
writer.write(getFormatter().format(record));
writer.flush();
@@ -74,7 +79,7 @@ public final class Log {
}
@Override
- public void flush() {
+ public synchronized void flush() {
if (writer != null) {
try {
writer.flush();
@@ -85,7 +90,7 @@ public final class Log {
}
@Override
- public void close() throws SecurityException {
+ public synchronized void close() throws SecurityException {
if (writer != null) {
try {
writer.close();