diff --git a/src/main/java/org/jitsi/utils/logging2/JitsiLogFormatter.java b/src/main/java/org/jitsi/utils/logging2/JitsiLogFormatter.java
index 80e1e3b..8e70b1a 100644
--- a/src/main/java/org/jitsi/utils/logging2/JitsiLogFormatter.java
+++ b/src/main/java/org/jitsi/utils/logging2/JitsiLogFormatter.java
@@ -17,10 +17,9 @@
package org.jitsi.utils.logging2;
import java.io.*;
-import java.text.*;
-import java.util.*;
+import java.time.*;
+import java.time.format.DateTimeFormatter;
import java.util.logging.*;
-import java.util.logging.Formatter;
public class JitsiLogFormatter extends Formatter
{
@@ -38,17 +37,7 @@ public class JitsiLogFormatter extends Formatter
/**
* Line separator used by current platform
*/
- private static String lineSeparator = System.getProperty("line.separator");
-
- /**
- * Two digit DecimalFormat instance, used to format datetime
- */
- private static DecimalFormat twoDigFmt = new DecimalFormat("00");
-
- /**
- * Three digit DecimalFormat instance, used to format datetime
- */
- private static DecimalFormat threeDigFmt = new DecimalFormat("000");
+ private static final String lineSeparator = System.lineSeparator();
/**
* The application name used to generate this log
@@ -60,6 +49,12 @@ public class JitsiLogFormatter extends Formatter
*/
private static boolean timestampDisabled = false;
+ /**
+ * The formatter to use for timestamps.
+ */
+ private static final DateTimeFormatter timestampFormatter =
+ DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS ");
+
/**
* The default constructor for JitsiLogFormatter which loads
* program name property from logging.properties file, if it exists
@@ -77,7 +72,7 @@ public JitsiLogFormatter()
@Override
public synchronized String format(LogRecord record)
{
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if (programName != null)
{
@@ -89,23 +84,7 @@ public synchronized String format(LogRecord record)
if (!timestampDisabled)
{
- //current time
- Calendar cal = Calendar.getInstance();
- int year = cal.get(Calendar.YEAR);
- int month = cal.get(Calendar.MONTH) + 1;
- int day = cal.get(Calendar.DAY_OF_MONTH);
- int hour = cal.get(Calendar.HOUR_OF_DAY);
- int minutes = cal.get(Calendar.MINUTE);
- int seconds = cal.get(Calendar.SECOND);
- int millis = cal.get(Calendar.MILLISECOND);
-
- sb.append(year).append('-');
- sb.append(twoDigFmt.format(month)).append('-');
- sb.append(twoDigFmt.format(day)).append(' ');
- sb.append(twoDigFmt.format(hour)).append(':');
- sb.append(twoDigFmt.format(minutes)).append(':');
- sb.append(twoDigFmt.format(seconds)).append('.');
- sb.append(threeDigFmt.format(millis)).append(' ');
+ sb.append(timestampFormatter.format(ZonedDateTime.ofInstant(record.getInstant(), ZoneId.systemDefault())));
}
//log level
@@ -151,9 +130,9 @@ public synchronized String format(LogRecord record)
PrintWriter pw = new PrintWriter(sw);
record.getThrown().printStackTrace(pw);
pw.close();
- sb.append(sw.toString());
+ sb.append(sw);
}
- catch (RuntimeException ex)
+ catch (RuntimeException ignored)
{
}
}