1 /*
2 * Copyright (c) 2003, Andreas Pataki
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * Neither the name of the author nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS
21 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 package net.sf.tm.plugin;
34
35 import org.eclipse.core.runtime.ILog;
36 import org.eclipse.core.runtime.IStatus;
37 import org.eclipse.core.runtime.Status;
38
39 /***
40 * A simple logger using the eclipse plugin login mechanism.
41 *
42 * @author Andreas Pataki
43 * @version $Id: Logger.java,v 1.1 2003/08/20 15:08:25 apataki Exp $
44 */
45 public final class Logger {
46
47 /***
48 * plugin log instance
49 */
50 private static ILog log;
51 /***
52 * value shows if debuggin is enabled
53 */
54 private static boolean debug;
55 /***
56 * ID of the plugin
57 */
58 private static String uniqueIdentifier;
59
60 /***
61 * Static initializer.
62 */
63 static {
64 log = ContextManagerPlugin.getDefault().getLog();
65 debug = ContextManagerPlugin.getDefault().isDebugging();
66 uniqueIdentifier =
67 ContextManagerPlugin
68 .getDefault()
69 .getDescriptor()
70 .getUniqueIdentifier();
71 }
72
73 /***
74 * hidden constructor
75 *
76 */
77 private Logger() {
78 }
79
80 /***
81 * Prints an error message to the Eclipse log.
82 *
83 * @param message error message
84 * @param exception catched exception
85 */
86 public static void error(String message, Throwable exception) {
87 log.log(
88 new Status(IStatus.ERROR, uniqueIdentifier, 0, message, exception));
89 }
90
91 /***
92 * Prints a debug statement to the Eclipse log.
93 *
94 * @param message error message
95 */
96 public static void debug(String message) {
97 if (debug) {
98 log.log(
99 new Status(IStatus.INFO, uniqueIdentifier, 0, message, null));
100
101 }
102 }
103
104 /***
105 * @return TRUE if tracing is enabled for the plugin
106 */
107 public static boolean isDebugEnabled() {
108 return debug;
109 }
110
111 }