Skip to content

Commit aaffa52

Browse files
committed
change date formatter to DateTimeFormatter
1 parent 0e1e919 commit aaffa52

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcRootLogger.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import java.nio.file.Path;
2323
import java.nio.file.Paths;
2424
import java.nio.file.StandardCopyOption;
25-
import java.text.SimpleDateFormat;
26-
import java.util.Date;
25+
import java.time.Instant;
26+
import java.time.ZoneId;
27+
import java.time.format.DateTimeFormatter;
2728
import java.util.Optional;
2829
import java.util.logging.ConsoleHandler;
2930
import java.util.logging.FileHandler;
@@ -62,7 +63,8 @@ class BigQueryJdbcRootLogger {
6263

6364
public static Formatter getFormatter() {
6465
return new Formatter() {
65-
private static final String PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
66+
private final DateTimeFormatter dateFormatter =
67+
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(ZoneId.systemDefault());
6668
private static final String FORMAT =
6769
"%1$s %2$5s %3$d --- [%4$-7.15s] %5$-50s %6$-20s: %7$s%8$s";
6870
private static final int MAX_THREAD_NAME_LENGTH = 15;
@@ -81,7 +83,9 @@ Optional<Thread> getThread(long threadId) {
8183

8284
@Override
8385
public String format(LogRecord record) {
84-
String date = new SimpleDateFormat(PATTERN).format(new Date(record.getMillis()));
86+
87+
String date = dateFormatter.format(Instant.ofEpochMilli(record.getMillis()));
88+
8589
String threadName =
8690
getThread(record.getThreadID())
8791
.map(Thread::getName)

0 commit comments

Comments
 (0)