Author: clebert.suconic(a)jboss.com
Date: 2011-06-16 20:31:24 -0400 (Thu, 16 Jun 2011)
New Revision: 10819
Modified:
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java
Log:
optimizing logger
Modified:
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java
===================================================================
---
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java 2011-06-17
00:01:21 UTC (rev 10818)
+++
branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java 2011-06-17
00:31:24 UTC (rev 10819)
@@ -14,8 +14,8 @@
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
import java.util.logging.LogRecord;
/**
@@ -25,18 +25,30 @@
{
private static String LINE_SEPARATOR =
System.getProperty("line.separator");
+ private String stripPackage(String clazzName)
+ {
+ return clazzName.substring(clazzName.lastIndexOf(".") + 1);
+ }
+
@Override
public String format(final LogRecord record)
{
- Date date = new Date();
- SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss,SSS");
+ Calendar calendar = GregorianCalendar.getInstance();
+ calendar.setTimeInMillis(record.getMillis());
+
StringBuffer sb = new StringBuffer();
- // Minimize memory allocations here.
- date.setTime(record.getMillis());
+
sb.append("[").append(Thread.currentThread().getName()).append("]
");
- sb.append(dateFormat.format(date)).append(" ");
+ sb.append(calendar.get(GregorianCalendar.HOUR_OF_DAY) + ":" +
+ calendar.get(GregorianCalendar.MINUTE) +
+ ":" +
+ calendar.get(GregorianCalendar.SECOND) +
+ "," +
+ calendar.get(GregorianCalendar.MILLISECOND) +
+ " ");
+
sb.append(record.getLevel()).append(" [");
- sb.append(record.getLoggerName()).append("]").append(" ");
+ sb.append(stripPackage(record.getLoggerName())).append("]").append("
");
sb.append(record.getMessage());
sb.append(HornetQLoggerFormatter.LINE_SEPARATOR);