Skip to content
Permalink
Browse files
Merge pull request #55 from jtnord/JENKINS-32622
[JENKINS-32622] Switch to a ThreadLocal DateFormatter
  • Loading branch information
christ66 committed Jan 27, 2016
2 parents 751b73f + bc9dc9d commit d0c2ec7b8acd28f088483e3d6ffec5fb3a157db7
Showing with 18 additions and 5 deletions.
  1. +18 −5 src/main/java/com/cloudbees/jenkins/support/SupportLogFormatter.java
@@ -24,22 +24,35 @@

package com.cloudbees.jenkins.support;

import org.apache.commons.lang.time.FastDateFormat;

/***********************************************
* DO NOT INCLUDE ANY NON JDK CLASSES IN HERE.
* IT CAN DEADLOCK REMOTING - SEE JENKINS-32622
***********************************************/
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
/***********************************************
* DO NOT INCLUDE ANY NON JDK CLASSES IN HERE.
* IT CAN DEADLOCK REMOTING - SEE JENKINS-32622
***********************************************/

/**
* Format log files in a nicer format that is easier to read and search.
*
* @author Stephen Connolly
*/
public class SupportLogFormatter extends Formatter {
FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ");

private final static ThreadLocal<SimpleDateFormat> threadLocalDateFormat = new ThreadLocal() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
}
};

private final Object[] args = new Object[6];

@Override
@@ -49,7 +62,7 @@
)
public String format(LogRecord record) {
StringBuilder builder = new StringBuilder();
builder.append(fdf.format(new Date(record.getMillis())));
builder.append(threadLocalDateFormat.get().format(new Date(record.getMillis())));
builder.append(" [id=").append(record.getThreadID()).append("]");

builder.append("\t").append(record.getLevel().getName()).append("\t");

0 comments on commit d0c2ec7

Please sign in to comment.