Permalink
Browse files

Tunneling all Java logging through LogAdapter, removing deprecated Er…

…rorManager. Display thread in log output.
  • Loading branch information...
1 parent effb966 commit 7db6cb417eabdefd2537403fd98340d04f67c974 ms140569 committed Jul 20, 2010
Showing with 207 additions and 132 deletions.
  1. +45 −0 netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/core/LogAdapter.java
  2. +6 −8 ...s/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/CljEditorContextImpl.java
  3. +7 −4 netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/CljSourcePath.java
  4. +12 −7 ...ugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/ClojureToolTipAnnotation.java
  5. +9 −7 ...ns/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/EditorContextBridge.java
  6. +4 −4 ...gins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/EngineContextProviderImpl.java
  7. +4 −2 netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/Installer.java
  8. +6 −7 netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/SourcePath.java
  9. +13 −13 ...plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/SourcePathProviderImpl.java
  10. +6 −4 .../org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/actions/AddClojureWatchAction.java
  11. +3 −3 ...clojure-plugin/src/main/java/org/enclojure/ide/debugger/breakpoints/ClojureBreakpointsReader.java
  12. +6 −1 ...-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/breakpoints/ClojureLineBreakpoint.java
  13. +4 −8 ...org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/breakpoints/PersistenceManager.java
  14. +4 −16 netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/debugger/util/Utils.java
  15. +5 −2 ...rg-enclojure-plugin/src/main/java/org/enclojure/ide/nb/clojure/project/ClojureActionProvider.java
  16. +4 −2 ...clojure-plugin/src/main/java/org/enclojure/ide/nb/clojure/project/ClojureTemplatePanelVisual.java
  17. +7 −4 ...jure-plugin/src/main/java/org/enclojure/ide/nb/clojure/project/ClojureTemplateWizardIterator.java
  18. +18 −11 ...ins/org-enclojure-plugin/src/main/java/org/enclojure/ide/nb/editor/ClojureMimeTypeDataObject.java
  19. +8 −7 netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/nb/editor/Installer.java
  20. +7 −4 ...eans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/nb/editor/ReplTopComponent.java
  21. +2 −3 ...-enclojure-plugin/src/main/java/org/enclojure/ide/nb/editor/completion/CljCompletionProvider.java
  22. +7 −3 ...lojure-plugin/src/main/java/org/enclojure/ide/nb/editor/completion/ClojureCodeCompletionItem.java
  23. +5 −2 ...e-plugin/src/main/java/org/enclojure/ide/nb/editor/completion/ClojureCodeCompletion_Provider.java
  24. +5 −3 ...plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/nb/source/CljSourceVisualPanel1.java
  25. +6 −5 ...ugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/nb/source/CljSourceWizardIterator.java
  26. +4 −2 ...plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/nb/source/CljSourceWizardPanel1.java
  27. BIN ...ain/resources/org/enclojure/ide/project/samples/ClojureProjectTemplate/ClojureProjectTemplate.zip
  28. BIN ...clojure-plugin/src/main/resources/org/enclojure/ide/templates/project/Clojure-1.1/Clojure-1.1.zip
  29. BIN .../main/resources/org/enclojure/ide/templates/project/Clojure-1.2-SNAPSHOT/Clojure-1.2-SNAPSHOT.zip
@@ -0,0 +1,45 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.enclojure.ide.core;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Adapter to act as a drop-in replacement for a Logger. The main purpose is to tweak the existing log(...)-methods
+ * to show more and detailed information about which Thread calls the logger. One might add things like the timestamp
+ * laster as well.
+ *
+ * @author Matthias Schmidt
+ */
+
+
+public class LogAdapter {
+
+ Logger LOG;
+
+ public LogAdapter(String name) {
+ LOG = Logger.getLogger(name);
+ LOG.setLevel(Level.ALL);
+ }
+
+ public void log(Level level, String msg){
+ LOG.log(level, formatter(msg));
+ }
+
+ public void log(Level level, String msg, Object param1){
+ LOG.log(level, formatter(msg), param1);
+ }
+
+ public void log(Level level, String msg, Object[] params){
+ LOG.log(level, formatter(msg), params);
+ }
+
+ private String formatter(String msg){
+ return Thread.currentThread().getName() + ":" + msg;
+ }
+
+}
@@ -55,9 +55,8 @@
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.enclojure.ide.core.LogAdapter;
import org.netbeans.api.debugger.DebuggerManager;
-import org.openide.ErrorManager;
import org.openide.cookies.EditorCookie;
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor;
@@ -66,8 +65,7 @@
@SuppressWarnings("unchecked")
public class CljEditorContextImpl extends EditorContext {
-
- private static Logger logger = Logger.getLogger("org.enclojure.clojure.debugger");
+ private static final LogAdapter LOG = new LogAdapter(CljEditorContextImpl.class.getName());
private static String fronting =
System.getProperty("netbeans.debugger.fronting");
@@ -148,7 +146,7 @@ public EditorContext proxy() {
*/
public boolean showSource(String url, int lineNumber, Object timeStamp) {
if(url != null && url.endsWith(".clj"))
- logger.log(Level.INFO,"Trying to show source for :"+url);
+ LOG.log(Level.INFO,"Trying to show source for :"+url);
return proxy().showSource(url, lineNumber, timeStamp);
}
@@ -611,7 +609,7 @@ public int getCurrentOffset() {
if (tex instanceof RuntimeException) {
throw (RuntimeException) tex;
} else {
- ErrorManager.getDefault().notify(tex);
+ LOG.log(Level.FINEST, tex.getMessage());
return 0;
}
} catch (Exception ex) {
@@ -627,11 +625,11 @@ public int getCurrentOffset() {
if (tex instanceof RuntimeException) {
throw (RuntimeException) tex;
} else {
- ErrorManager.getDefault().notify(tex);
+ LOG.log(Level.FINEST, tex.getMessage());
return 0;
}
} catch (Exception ex) {
- ErrorManager.getDefault().notify(ex);
+ LOG.log(Level.FINEST, ex.getMessage());
return 0;
}
}
@@ -70,11 +70,14 @@
import org.netbeans.spi.debugger.jpda.EditorContext;
import org.netbeans.spi.debugger.jpda.EditorContext.Operation;
import org.netbeans.spi.debugger.jpda.SourcePathProvider;
-import org.openide.ErrorManager;
+import java.util.logging.Level;
+import org.enclojure.ide.core.LogAdapter;
@SuppressWarnings("unchecked")
public class CljSourcePath {
+ private static final LogAdapter LOG = new LogAdapter(CljSourcePath.class.getName());
+
private ContextProvider contextProvider;
private SourcePathProvider sourcePathProvider;
private JPDADebugger debugger;
@@ -283,7 +286,7 @@ public boolean showSource(CallStackFrame csf, String stratumn) {
convertSlash(csf.getSourcePath(stratumn)), true);
}
if (url == null) {
- ErrorManager.getDefault().log(ErrorManager.WARNING,
+ LOG.log(Level.WARNING,
"Show Source: No URL for source path " + csf.getSourcePath(stratumn) +
"\nThe reason is likely no opened project for this source file.");
return false;
@@ -300,7 +303,7 @@ public boolean showSource(CallStackFrame csf, String stratumn) {
String url = getURL(
convertClassNameToRelativePath(csf.getClassName()), true);
if (url == null) {
- ErrorManager.getDefault().log(ErrorManager.WARNING,
+ LOG.log(Level.WARNING,
"Show Source: No source URL for class " + csf.getClassName() +
"\nThe reason is likely no opened project for the source file.");
return false;
@@ -339,7 +342,7 @@ private static String convertSlash(String original) {
public static String convertClassNameToRelativePath(
String className) {
- ErrorManager.getDefault().log(ErrorManager.WARNING,
+ LOG.log(Level.WARNING,
"convertClassNameToRelativePath called for class " + className);
return "";
}
@@ -60,15 +60,20 @@
import org.netbeans.api.debugger.*;
import org.netbeans.api.debugger.jpda.*;
import org.openide.loaders.DataObject;
+import org.enclojure.ide.core.LogAdapter;
+import java.util.logging.Level;
+
public class ClojureToolTipAnnotation extends Annotation implements Runnable {
+
+ private static final LogAdapter LOG = new LogAdapter(ClojureToolTipAnnotation.class.getName());
private String toolTipText = null;
private StyledDocument doc;
public String getShortDescription() {
- Utils.log("ClojureTooltip: getShortDescription");
+ LOG.log(Level.FINEST, "ClojureTooltip: getShortDescription");
toolTipText = null;
DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager ().
@@ -96,7 +101,7 @@ public String getShortDescription() {
public void run () {
- Utils.log("ClojureTooltip: run");
+ LOG.log(Level.FINEST, "ClojureTooltip: run");
//1) get tooltip text
Line.Part lp = (Line.Part)getAttachedAnnotatable();
@@ -109,20 +114,20 @@ public void run () {
//first try EL
String text = Utils.getELIdentifier(doc, ep,NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn());
- Utils.log("JspToClojureTooltipoltip: ELIdentifier = " + text);
+ LOG.log(Level.FINEST, "JspToClojureTooltipoltip: ELIdentifier = " + text);
boolean isScriptlet = Utils.isScriptlet(
doc, ep, NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn()
);
- Utils.log("isScriptlet: " + isScriptlet);
+ LOG.log(Level.FINEST, "isScriptlet: " + isScriptlet);
//if not, try Java
if ((text == null) && (isScriptlet)) {
text = Utils.getJavaIdentifier(
doc, ep, NbDocument.findLineOffset(doc, lp.getLine().getLineNumber()) + lp.getColumn()
);
textForTooltip = text;
- Utils.log("ClojureTooltip: javaIdentifier = " + text);
+ LOG.log(Level.FINEST, "ClojureTooltip: javaIdentifier = " + text);
if (text == null) {
return;
}
@@ -136,7 +141,7 @@ public void run () {
"\", java.lang.String.class, (javax.servlet.jsp.PageContext)pageContext, null)";
}
- Utils.log("JspTooltip: fullWatch = " + text);
+ LOG.log(Level.FINEST, "JspTooltip: fullWatch = " + text);
//3) obtain text representation of value of watch
String old = toolTipText;
@@ -157,7 +162,7 @@ public void run () {
} catch (InvalidExpressionException e) {
toolTipText = text + " = >" + e.getMessage() + "<";
}
- Utils.log("ClojureTooltip: " + toolTipText);
+ LOG.log(Level.FINEST, "ClojureTooltip: " + toolTipText);
firePropertyChange (PROP_SHORT_DESCRIPTION, old, toolTipText);
}
@@ -62,11 +62,14 @@
import org.netbeans.api.debugger.jpda.JPDAThread;
import org.netbeans.spi.debugger.jpda.EditorContext;
import org.netbeans.spi.debugger.jpda.EditorContext.Operation;
-import org.openide.ErrorManager;
+import java.util.logging.Level;
+import org.enclojure.ide.core.LogAdapter;
public class EditorContextBridge {
+ private static final LogAdapter LOG = new LogAdapter(EditorContextBridge.class.getName());
+
public static final String FIELD = "field";
public static final String METHOD = "method";
public static final String CLASS = "class";
@@ -159,11 +162,11 @@ public static int getCurrentOffset() {
if (tex instanceof RuntimeException) {
throw (RuntimeException) tex;
} else {
- ErrorManager.getDefault().notify(tex);
+ LOG.log(Level.FINEST, tex.getMessage());
return 0;
}
} catch (Exception ex) {
- ErrorManager.getDefault().notify(ex);
+ LOG.log(Level.FINEST, ex.getMessage());
return 0;
}
}
@@ -236,12 +239,11 @@ public int getCurrentOffset() {
if (tex instanceof RuntimeException) {
throw (RuntimeException) tex;
} else {
- ErrorManager.getDefault().notify(tex);
+ LOG.log(Level.FINEST, tex.getMessage());
return 0;
}
} catch (Exception ex) {
// Ignore, we have another attempt with cp2
- //ErrorManager.getDefault().notify(ex);
}
if (i == null || i.intValue() < 1) {
try {
@@ -252,11 +254,11 @@ public int getCurrentOffset() {
if (tex instanceof RuntimeException) {
throw (RuntimeException) tex;
} else {
- ErrorManager.getDefault().notify(tex);
+ LOG.log(Level.FINEST, tex.getMessage());
return 0;
}
} catch (Exception ex) {
- ErrorManager.getDefault().notify(ex);
+ LOG.log(Level.FINEST, ex.getMessage());
return 0;
}
}
@@ -49,7 +49,7 @@
package org.enclojure.ide.debugger;
import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.enclojure.ide.core.LogAdapter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -71,9 +71,9 @@
public class EngineContextProviderImpl extends SourcePathProvider {
private static boolean verbose =
- System.getProperty ("netbeans.debugger.enginecontextproviderimpl") != null;
+ System.getProperty ("netbeans.debugger.enginecontextproviderimpl") != null;
- private static Logger logger = Logger.getLogger("org.enclojure.clojure.debugger");
+ private static final LogAdapter LOG = new LogAdapter(EngineContextProviderImpl.class.getName());
private static final Pattern thisDirectoryPattern = Pattern.compile("(/|\\A)\\./");
private static final Pattern parentDirectoryPattern = Pattern.compile("(/|\\A)([^/]+?)/\\.\\./");
@@ -128,7 +128,7 @@ public String getURL (String relativePath,boolean notSure) {
if(fo != null)
return fo.getURL ().toString ();
} catch(Exception e) {
- logger.log(Level.WARNING,"cannot find URL for "+relativePath);
+ LOG.log(Level.WARNING,"cannot find URL for "+relativePath);
}
}
return null;
@@ -19,19 +19,21 @@
package org.enclojure.ide.debugger;
import java.util.logging.Logger;
+import org.enclojure.ide.core.LogAdapter;
+import java.util.logging.Level;
import org.openide.modules.ModuleInstall;
public class Installer extends ModuleInstall {
- final Logger cljLog = Logger.getLogger("org.enclojure.clojure.debugger");
+ private static final LogAdapter LOG = new LogAdapter(Installer.class.getName());
@Override
public void restored() {
try {
Logger logger = Logger.getLogger("org.netbeans.modules.debugger.jpda.breakpoints");
logger.setLevel(java.util.logging.Level.ALL );
} catch(Exception e) {
- cljLog.throwing("org.enclojure.clojure.debugger.Installer", "restored",e);
+ LOG.log(Level.SEVERE, "restored", e);
}
}
}
@@ -55,7 +55,7 @@
import java.io.File;
import java.util.List;
import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.enclojure.ide.core.LogAdapter;
import org.netbeans.spi.debugger.ContextProvider;
import org.netbeans.api.debugger.jpda.CallStackFrame;
@@ -68,6 +68,8 @@
public class SourcePath {
+ private static final LogAdapter LOG = new LogAdapter(SourcePath.class.getName());
+
private ContextProvider lookupProvider;
private SourcePathProvider contextProvider;
private JPDADebugger debugger;
@@ -142,8 +144,7 @@ public String getURL (String relativePath, boolean global) {
try {
new java.net.URL(url);
} catch (java.net.MalformedURLException muex) {
- Logger.getLogger(SourcePath.class.getName()).log(Level.WARNING,
- "Malformed URL '"+url+"' produced by "+getContext (), muex);
+ LOG.log(Level.WARNING, "Malformed URL '"+url+"' produced by "+getContext (), muex);
return null;
}
}
@@ -431,17 +432,15 @@ public String getURL (String relativePath, boolean global) {
new java.net.URL(p1);
return p1;
} catch (java.net.MalformedURLException muex) {
- Logger.getLogger(SourcePath.class.getName()).log(Level.WARNING,
- "Malformed URL '"+p1+"' produced by "+cp1, muex);
+ LOG.log(Level.WARNING, "Malformed URL '"+p1+"' produced by "+cp1, muex);
}
}
p1 = cp2.getURL (relativePath, global);
if (p1 != null) {
try {
new java.net.URL(p1);
} catch (java.net.MalformedURLException muex) {
- Logger.getLogger(SourcePath.class.getName()).log(Level.WARNING,
- "Malformed URL '"+p1+"' produced by "+cp2, muex);
+ LOG.log(Level.WARNING, "Malformed URL '"+p1+"' produced by "+cp2, muex);
p1 = null;
}
}
Oops, something went wrong.

0 comments on commit 7db6cb4

Please sign in to comment.