package org.tinylog.benchmarks.logging.jul_____;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

import org.tinylog.benchmarks.logging.core.LocationInfo;

/**
 * Simple formatter for formatting log records for java.util.logging.
 */
public class SimpleFormatter extends Formatter {

	private static final String NEW_LINE = System.lineSeparator();
	private static final String SEPARATOR = " - ";

	private final LocationInfo locationInfo;
	private final DateTimeFormatter formatter;

	/**
	 * @param locationInfo The location information to output
	 */
	public SimpleFormatter(final LocationInfo locationInfo) {
		this.locationInfo = locationInfo;
		this.formatter = DateTimeFormatter
			.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.US)
			.withZone(ZoneId.systemDefault());
	}

	@Override
	public String format(final LogRecord record) {
		StringBuilder builder = new StringBuilder();
		formatter.formatTo(record.getInstant(), builder);
		builder.append(SEPARATOR);
		builder.append(Thread.currentThread().getName());

		if (locationInfo == LocationInfo.FULL) {
			builder.append(SEPARATOR);
			builder.append(record.getSourceClassName());
			builder.append(".");
			builder.append(record.getSourceMethodName());
			builder.append("()");
		} else if (locationInfo == LocationInfo.CLASS_OR_CATEGORY_ONLY) {
			builder.append(SEPARATOR);
			builder.append(record.getLoggerName());
		}

		builder.append(SEPARATOR);
		builder.append(record.getLevel());
		builder.append(": ");
		builder.append(formatMessage(record));

		if (record.getThrown() != null) {
			StringWriter stringWriter = new StringWriter();
			PrintWriter printWriter = new PrintWriter(stringWriter);
			printWriter.println();
			record.getThrown().printStackTrace(printWriter);
			printWriter.close();
			builder.append(stringWriter);
		}

		builder.append(NEW_LINE);

		return builder.toString();
	}

}

@@ -117,18 +117,28 @@
 va.t
-ime.ZoneId
+ext.SimpleDateFormat
 ;%0Aim
@@ -151,37 +151,17 @@
 ava.
+u
 ti
-me.format.DateTimeFormatter
+l.Date
 ;%0Aim
@@ -612,33 +612,32 @@
 e final 
-DateTim
+SimpleDat
 eFormat
-ter
  formatt
@@ -828,39 +828,28 @@
 r = 
-DateTimeFormatter%0A%09%09%09.ofPattern
+new SimpleDateFormat
 (%22yy
@@ -882,45 +882,8 @@
 .US)
-%0A%09%09%09.withZone(ZoneId.systemDefault())
 ;%0A%09%7D
@@ -994,59 +994,109 @@
 ();%0A
+%0A
 %09%09
-formatter.formatTo(record.getInstant(), builder);
+synchronized (formatter) %7B%0A%09%09%09builder.append(formatter.format(new Date(record.getMillis())));%0A%09%09%7D%0A
 %0A%09%09b

Fix building simple formatter with JDK 8 for JUL benchmark