summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-02-24 05:59:23 (EST)
committerEike Stepper2007-02-24 05:59:23 (EST)
commitedb1c1b2d1a9f0a9886f8c188ee1ce15bc498f02 (patch)
tree67cf7385a811d13ba26388aa38134f823419fb42
parent82aa1a4400cc7eb890a60106ab3c9ebeebc9a2ed (diff)
downloadcdo-edb1c1b2d1a9f0a9886f8c188ee1ce15bc498f02.zip
cdo-edb1c1b2d1a9f0a9886f8c188ee1ce15bc498f02.tar.gz
cdo-edb1c1b2d1a9f0a9886f8c188ee1ce15bc498f02.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java1
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java89
2 files changed, 79 insertions, 11 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java
index b7e9354..5fe69cb 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Activator.java
@@ -24,6 +24,7 @@ public class Activator implements BundleActivator
public void start(BundleContext context) throws Exception
{
AbstractOMPlatform.systemContext = context;
+ PrintTraceHandler.CONSOLE.setPattern("{6} [{0}] {5}");
AbstractOMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
AbstractOMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
Net4j.BUNDLE.setBundleContext(context);
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java
index f968293..f8dc1a5 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java
@@ -12,8 +12,10 @@ package org.eclipse.net4j.util.om.trace;
import org.eclipse.net4j.util.IOUtil;
import org.eclipse.net4j.util.om.OMTraceHandler;
+import org.eclipse.net4j.util.om.OMTracer;
import java.io.PrintStream;
+import java.text.MessageFormat;
/**
* @author Eike Stepper
@@ -24,6 +26,8 @@ public class PrintTraceHandler implements OMTraceHandler
private PrintStream stream;
+ private String pattern;
+
private boolean shortContext;
public PrintTraceHandler(PrintStream stream)
@@ -36,6 +40,32 @@ public class PrintTraceHandler implements OMTraceHandler
this(IOUtil.OUT());
}
+ public String getPattern()
+ {
+ return pattern;
+ }
+
+ /**
+ * Pattern arguments:
+ * <p>
+ * <ul>
+ * <li>{0} --> String <b>tracerName</b><br>
+ * <li>{1} --> String <b>tracerShort</b><br>
+ * <li>{2} --> String <b>contextName</b><br>
+ * <li>{3} --> String <b>contextShort</b><br>
+ * <li>{4} --> long <b>timeStamp</b><br>
+ * <li>{5} --> String <b>message</b><br>
+ * <li>{6} --> String <b>threadName</b><br>
+ * <li>{7} --> long <b>threadID</b><br>
+ * <li>{8} --> int <b>threadPriority</b><br>
+ * <li>{9} --> Thread.State <b>threadState</b><br>
+ * </ul>
+ */
+ public void setPattern(String pattern)
+ {
+ this.pattern = pattern;
+ }
+
public boolean isShortContext()
{
return shortContext;
@@ -48,20 +78,57 @@ public class PrintTraceHandler implements OMTraceHandler
public void traced(Event event)
{
- String context = event.getContext().getName();
- if (shortContext)
- {
- int pos = Math.max(context.lastIndexOf('.'), context.lastIndexOf('$'));
- if (pos != -1)
- {
- context = context.substring(pos + 1);
- }
- }
-
- stream.println(Thread.currentThread().getName() + " [" + context + "] " + event.getMessage()); //$NON-NLS-1$
+ String line = pattern == null ? format(shortContext, event) : format(pattern, event);
+ stream.println(line);
if (event.getThrowable() != null)
{
IOUtil.print(event.getThrowable(), stream);
}
}
+
+ public static String format(boolean shortContext, Event event)
+ {
+ Class context = event.getContext();
+ String contextName = shortContext ? context.getSimpleName() : context.getName();
+ return Thread.currentThread().getName() + " [" + contextName + "] " + event.getMessage();
+ }
+
+ /**
+ * Pattern arguments:
+ * <p>
+ * <ul>
+ * <li>{0} --> String <b>tracerName</b><br>
+ * <li>{1} --> String <b>tracerShort</b><br>
+ * <li>{2} --> String <b>contextName</b><br>
+ * <li>{3} --> String <b>contextShort</b><br>
+ * <li>{4} --> long <b>timeStamp</b><br>
+ * <li>{5} --> String <b>message</b><br>
+ * <li>{6} --> String <b>threadName</b><br>
+ * <li>{7} --> long <b>threadID</b><br>
+ * <li>{8} --> int <b>threadPriority</b><br>
+ * <li>{9} --> Thread.State <b>threadState</b><br>
+ * </ul>
+ */
+ public static String format(String pattern, Event event)
+ {
+ final OMTracer tracer = event.getTracer();
+ final String tracerName = tracer.getFullName();
+ final String tracerShort = tracer.getName();
+
+ final Class context = event.getContext();
+ final String contextName = context.getName();
+ final String contextShort = context.getName();
+
+ final long timeStamp = event.getTimeStamp();
+ final String message = event.getMessage();
+
+ final Thread thread = Thread.currentThread();
+ final String threadName = thread.getName();
+ final long threadID = thread.getId();
+ final int threadPriority = thread.getPriority();
+ final Thread.State threadState = thread.getState();
+
+ return MessageFormat.format(pattern, tracerName, tracerShort, contextName, contextShort, timeStamp, message,
+ threadName, threadID, threadPriority, threadState);
+ }
}