Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 402392f1eae4b89cf8d95c5b167010d361e94e7c (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***************************************************************************
 * Copyright (c) 2004, 2005, 2006 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.internal.net4j.bundle;

import org.eclipse.net4j.util.om.OMBundle;
import org.eclipse.net4j.util.om.OMTracer;
import org.eclipse.net4j.util.om.OMTraceHandler.Event;

import java.text.MessageFormat;

/**
 * @author Eike Stepper
 */
public class OMTracerImpl implements OMTracer
{
  private OMBundle bundle;

  private OMTracerImpl parent;

  private String name;

  private String fullName;

  public OMTracerImpl(OMBundle bundle, String name)
  {
    this.bundle = bundle;
    this.name = name;
    fullName = name;
  }

  private OMTracerImpl(OMTracerImpl parent, String name)
  {
    this.bundle = parent.getBundle();
    this.parent = parent;
    this.name = name;
    fullName = parent.getFullName() + "." + name; //$NON-NLS-1$
  }

  public OMBundle getBundle()
  {
    return bundle;
  }

  public OMTracer getParent()
  {
    return parent;
  }

  public String getName()
  {
    return name;
  }

  public String getFullName()
  {
    return fullName;
  }

  public boolean isEnabled()
  {
    return bundle.isDebugging() && bundle.getDebugOption(fullName, false);
  }

  public void setEnabled(boolean enabled)
  {
    bundle.setDebugOption(fullName, enabled);
  }

  public void trace(Event event)
  {
    ((AbstractOMPlatform)bundle.getPlatform()).trace(event);
  }

  public Event trace(Class context, String msg, Throwable t)
  {
    Event event = new OMTraceHandlerEventImpl(this, context, msg, t);
    trace(event);
    return event;
  }

  public Event format(Class context, String pattern, Throwable t, Object... args)
  {
    String msg = MessageFormat.format(pattern, args);
    return trace(context, msg, t);
  }

  public Event format(Class context, String pattern, Object... args)
  {
    return format(context, pattern, (Throwable)null, args);
  }

  public Event trace(Class context, String msg)
  {
    return trace(context, msg, (Throwable)null);
  }

  public Event trace(Class context, Throwable t)
  {
    return trace(context, (String)null, t);
  }

  public OMTracer tracer(String name)
  {
    return new OMTracerImpl(this, name);
  }
}

Back to the top