write exceptions to log instead of printing to console

This commit is contained in:
Eugene Kudelevsky
2010-07-19 13:17:37 +04:00
parent edef28b37b
commit 11e54329c7
5 changed files with 36 additions and 22 deletions
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.analysis.CreateNSDeclarationIntentionFix;
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
import com.intellij.lang.xml.XMLLanguage;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
@@ -44,6 +45,8 @@ import org.jetbrains.annotations.Nullable;
* Date: 24.07.2007
*/
public class PrefixReferenceProvider extends PsiReferenceProviderBase {
private static final Logger LOG = Logger.getInstance("#org.intellij.plugins.relaxNG.references.PrefixReferenceProvider");
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
final XmlAttributeValue value = (XmlAttributeValue)element;
@@ -102,7 +105,7 @@ public class PrefixReferenceProvider extends PsiReferenceProviderBase {
QuickFixAction.registerQuickFixAction(info,
new CreateNSDeclarationIntentionFix(tag, reference.getCanonicalText()));
} catch (Throwable e) {
e.printStackTrace();
LOG.error(e);
}
}
@@ -17,7 +17,9 @@
package org.intellij.plugins.relaxNG.validation;
import com.intellij.ide.errorTreeView.NewErrorTreeViewPanel;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Key;
@@ -33,7 +35,6 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.swing.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
@@ -44,6 +45,8 @@ import java.util.Set;
* Date: 19.11.2007
*/
public class MessageViewHelper {
private static final Logger LOG = Logger.getInstance("#org.intellij.plugins.relaxNG.validation.MessageViewHelper");
private final Project myProject;
private final Set<String> myErrors = new THashSet<String>();
@@ -91,23 +94,23 @@ public class MessageViewHelper {
try {
file = VfsUtil.findFileByURL(new URL(systemId));
} catch (MalformedURLException e) {
System.err.println("systemId = " + systemId);
e.printStackTrace();
LOG.warn("systemId = " + systemId);
LOG.error(e);
}
}
final VirtualFile file1 = file;
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
myErrorsView.addMessage(
warning ? MessageCategory.WARNING : MessageCategory.ERROR,
new String[]{ ex.getLocalizedMessage() },
file1,
ex.getLineNumber() - 1,
ex.getColumnNumber() - 1, null);
}
}
ApplicationManager.getApplication().invokeLater(
new Runnable() {
public void run() {
myErrorsView.addMessage(
warning ? MessageCategory.WARNING : MessageCategory.ERROR,
new String[]{ex.getLocalizedMessage()},
file1,
ex.getLineNumber() - 1,
ex.getColumnNumber() - 1, null);
}
}
);
}
@@ -16,6 +16,7 @@
package org.intellij.plugins.relaxNG.validation;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
@@ -62,12 +63,15 @@ import java.io.StringReader;
* Date: 19.07.2007
*/
public class RngParser {
private static final Logger LOG = Logger.getInstance("#org.intellij.plugins.relaxNG.validation.RngParser");
static final Key<CachedValue<Schema>> SCHEMA_KEY = Key.create("SCHEMA");
static final Key<CachedValue<DPattern>> PATTERN_KEY = Key.create("PATTERN");
public static final DefaultHandler DEFAULT_HANDLER = new DefaultHandler() {
public void error(SAXParseException e) throws SAXException {
System.out.println("e.getMessage() = " + e.getMessage() + " [" + e.getSystemId() + "]");
LOG.info("e.getMessage() = " + e.getMessage() + " [" + e.getSystemId() + "]");
LOG.info(e);
}
};
@@ -90,9 +94,9 @@ public class RngParser {
return (DPattern)p.parse(checking ? new CheckingSchemaBuilder(sb, eh) : sb);
} catch (BuildException e) {
e.printStackTrace();
LOG.info(e);
} catch (IllegalSchemaException e) {
System.out.println("invalid schema: " + file.getVirtualFile().getPresentableUrl());
LOG.info("invalid schema: " + file.getVirtualFile().getPresentableUrl());
}
return null;
}
@@ -166,7 +170,7 @@ public class RngParser {
return Result.createSingleDependency(schema, descriptorFile);
}
} catch (Exception e) {
e.printStackTrace();
LOG.info(e);
return Result.createSingleDependency(null, descriptorFile);
}
}
@@ -17,6 +17,7 @@
package org.intellij.plugins.relaxNG.validation;
import com.intellij.codeInsight.daemon.Validator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.psi.PsiDocumentManager;
@@ -40,6 +41,7 @@ import org.xml.sax.SAXParseException;
* Date: 30.07.2007
*/
public class XmlInstanceValidator {
private static final Logger LOG = Logger.getInstance("#org.intellij.plugins.relaxNG.validation.MessageViewHelper");
public static void doValidation(@NotNull final XmlDocument doc, final Validator.ValidationHost host, final XmlFile descriptorFile) {
try {
@@ -61,9 +63,11 @@ public class XmlInstanceValidator {
doc.accept(new Psi2SaxAdapter(handler));
} catch (ProcessCanceledException e) {
throw e;
LOG.error(e);
} catch (RuntimeException e) {
LOG.error(e);
} catch (Exception e) {
e.printStackTrace();
LOG.info(e);
}
}
@@ -85,7 +85,7 @@ public abstract class HighlightingTestBase extends TestCase implements IdeaCodeI
}
});
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}