01: package com.caucho.netbeans;
02:
03: import org.openide.ErrorManager;
04:
05: import java.io.IOException;
06: import java.util.logging.Level;
07: import java.util.logging.LogManager;
08:
09: public class PluginLogger {
10: private final ErrorManager _errorManager;
11:
12: private static final boolean _isDebug = true;
13:
14: public PluginLogger(Class<?> cl) {
15: String name = cl.getName();
16:
17: _errorManager = ErrorManager.getDefault().getInstance(name);
18: }
19:
20: public void log(Level level, String msg) {
21: _errorManager.log(getLevel(level), msg);
22: }
23:
24: public void log(Level level, Throwable t) {
25: _errorManager.notify(getLevel(level), t);
26: }
27:
28: private int getLevel(Level level) {
29: if (level.intValue() >= Level.SEVERE.intValue())
30: return ErrorManager.ERROR;
31: else if (level.intValue() >= Level.WARNING.intValue())
32: return ErrorManager.EXCEPTION;
33: else if (level.intValue() >= Level.INFO.intValue())
34: return ErrorManager.USER;
35: else
36: return ErrorManager.INFORMATIONAL;
37: }
38:
39: public boolean isLoggable(Level level) {
40: return _errorManager.isLoggable(getLevel(level));
41: }
42:
43: static {
44: if (_isDebug) {
45: System.setProperty("com.caucho.level", "0");
46:
47: try {
48: LogManager.getLogManager().readConfiguration();
49: } catch (IOException e) {
50: // no-op
51: }
52: }
53: }
54:
55: }
|