Skip to content

Commit

Permalink
Merge pull request #55 from jtnord/JENKINS-32622
Browse files Browse the repository at this point in the history
[JENKINS-32622] Switch to a ThreadLocal DateFormatter
  • Loading branch information
christ66 committed Jan 27, 2016
2 parents 751b73f + bc9dc9d commit d0c2ec7
Showing 1 changed file with 18 additions and 5 deletions.
Expand Up @@ -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
Expand All @@ -49,7 +62,7 @@ public class SupportLogFormatter extends Formatter {
)
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");
Expand Down

0 comments on commit d0c2ec7

Please sign in to comment.