Author: clebert.suconic(a)jboss.com
Date: 2011-08-08 13:51:00 -0400 (Mon, 08 Aug 2011)
New Revision: 11149
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java
Log:
Optimizing logger for tests
Modified:
branches/Branch_2_2_EAP/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java
===================================================================
---
branches/Branch_2_2_EAP/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java 2011-08-08
16:18:22 UTC (rev 11148)
+++
branches/Branch_2_2_EAP/src/main/org/hornetq/integration/logging/HornetQLoggerFormatter.java 2011-08-08
17:51:00 UTC (rev 11149)
@@ -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,34 @@
{
private static String LINE_SEPARATOR =
System.getProperty("line.separator");
+ private String stripPackage(String clazzName)
+ {
+ return clazzName.substring(clazzName.lastIndexOf(".") + 1);
+ }
+
+ private static String [] MONTHS = {"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"};
+
@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("* [").append(Thread.currentThread().getName()).append("]
");
+ sb.append(calendar.get(GregorianCalendar.DAY_OF_MONTH) + "-" +
MONTHS[calendar.get(GregorianCalendar.MONTH)] + " " +
+ 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(HornetQLoggerFormatter.LINE_SEPARATOR);
sb.append(record.getMessage());
sb.append(HornetQLoggerFormatter.LINE_SEPARATOR);
@@ -46,14 +62,22 @@
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
- record.getThrown().printStackTrace(pw);
+
+ pw.println(record.getThrown() );
+ StackTraceElement[] trace = record.getThrown().getStackTrace();
+ for (int i=0; i < trace.length; i++)
+ pw.println("\tat " + trace[i]);
pw.close();
+
sb.append(sw.toString());
}
catch (Exception ex)
{
}
}
+
+ sb.append(HornetQLoggerFormatter.LINE_SEPARATOR);
+
return sb.toString();
}
Show replies by date