blob: f9682939581c525e9a90115e5c971b36f7e9e8c9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/***************************************************************************
* Copyright (c) 2004-2007 Eike Stepper, Germany.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
package org.eclipse.net4j.util.om.trace;
import org.eclipse.net4j.util.IOUtil;
import org.eclipse.net4j.util.om.OMTraceHandler;
import java.io.PrintStream;
/**
* @author Eike Stepper
*/
public class PrintTraceHandler implements OMTraceHandler
{
public static final PrintTraceHandler CONSOLE = new PrintTraceHandler();
private PrintStream stream;
private boolean shortContext;
public PrintTraceHandler(PrintStream stream)
{
this.stream = stream;
}
protected PrintTraceHandler()
{
this(IOUtil.OUT());
}
public boolean isShortContext()
{
return shortContext;
}
public void setShortContext(boolean shortContext)
{
this.shortContext = shortContext;
}
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$
if (event.getThrowable() != null)
{
IOUtil.print(event.getThrowable(), stream);
}
}
}
|