1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.geronimo.st.ui.internal; 18 19 import org.apache.geronimo.st.ui.Activator; 20 import org.eclipse.core.runtime.IStatus; 21 22 23 /** 24 * Helper class to route trace output. 25 * 26 * @version $Rev: 817996 $ $Date: 2009-09-23 16:04:12 +0800 (Wed, 23 Sep 2009) $ 27 */ 28 public class Trace { 29 30 /** 31 * Finest trace event. 32 */ 33 public static byte INFO = 0; 34 35 /** 36 * Warning trace event. 37 */ 38 public static byte WARNING = 1; 39 40 /** 41 * Severe trace event. 42 */ 43 public static byte SEVERE = 2; 44 45 /** 46 * Trace constructor comment. 47 */ 48 private Trace() { 49 super(); 50 } 51 52 /** 53 * Trace the given text. 54 * 55 * @param level 56 * the trace level 57 * @param s 58 * a message 59 */ 60 public static void trace(byte level, String s) { 61 trace(level, s, null); 62 } 63 64 /** 65 * Trace the given message and exception. 66 * 67 * @param level 68 * the trace level 69 * @param s 70 * a message 71 * @param t 72 * a throwable 73 */ 74 public static void trace(byte level, String s, Throwable t) { 75 if (!Activator.getDefault().isDebugging()) 76 return; 77 78 System.out.println(Activator.PLUGIN_ID + ": " + s); 79 if (t != null) 80 t.printStackTrace(); 81 82 } 83 84 /** 85 * Trace the given message 86 * 87 * @param tracePoint 88 * The trace point (e.g., "Exit", "Entry", "Constructor", etc.... 89 * 90 * @param classDotMethod 91 * The class name + method name (e.g., "Class.method()") 92 * 93 * @param parms 94 * Method parameter(s) if the trace point is an "Entry" 95 * or 96 * Return value if the trace point is an "Exit" 97 */ 98 public static void tracePoint(String tracePoint, String classDotMethod) { 99 trace(Trace.INFO, tracePoint + ": " + classDotMethod + "()" ); 100 } 101 public static void tracePoint(String tracePoint, String classDotMethod, Object... parms) { 102 if ( parms == null ) { 103 trace(Trace.INFO, tracePoint + ": " + classDotMethod + "( null )" ); 104 } 105 else { 106 trace(Trace.INFO, tracePoint + ": " + classDotMethod + "(" ); 107 for ( int ii=0; ii<parms.length; ii++) { 108 Object parm = parms[ii]; 109 trace(Trace.INFO, " parm" + (ii+1) + "=[" + (parm == null ? null : parm.toString()) + "]" ); 110 } 111 trace(Trace.INFO, ")" ); 112 } 113 } 114 }