Added exception logging (see request 753883)

This commit is contained in:
Oleg Sukhodolsky 2003-09-03 04:35:40 +00:00
parent 39c810009d
commit 1e7bbb8cd8
5 changed files with 30 additions and 0 deletions

View File

@ -215,6 +215,8 @@ public final class TreeWalker
walk(rootAST, contents);
}
catch (FileNotFoundException fnfe) {
Utils.getExceptionLogger()
.debug("FileNotFoundException occured.", fnfe);
getMessageCollector().add(
new LocalizedMessage(
0,
@ -224,6 +226,7 @@ public final class TreeWalker
this.getClass()));
}
catch (IOException ioe) {
Utils.getExceptionLogger().debug("IOException occured.", ioe);
getMessageCollector().add(
new LocalizedMessage(
0,
@ -233,6 +236,8 @@ public final class TreeWalker
this.getClass()));
}
catch (RecognitionException re) {
Utils.getExceptionLogger()
.debug("RecognitionException occured.", re);
getMessageCollector().add(
new LocalizedMessage(
0,
@ -242,6 +247,8 @@ public final class TreeWalker
this.getClass()));
}
catch (TokenStreamException te) {
Utils.getExceptionLogger()
.debug("TokenStreamException occured.", te);
getMessageCollector().add(
new LocalizedMessage(
0,
@ -251,6 +258,7 @@ public final class TreeWalker
this.getClass()));
}
catch (Throwable err) {
Utils.getExceptionLogger().debug("Throwable occured.", err);
getMessageCollector().add(
new LocalizedMessage(
0,

View File

@ -30,6 +30,9 @@ import org.apache.commons.beanutils.ConversionException;
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Contains utility methods.
*
@ -40,6 +43,9 @@ public final class Utils
{
/** Map of all created regular expressions **/
private static final Map CREATED_RES = new HashMap();
/** Shared instance of logger for exception logging. */
private static final Log EXCEPTION_LOG =
LogFactory.getLog("com.puppycrawl.tools.checkstyle.ExceptionLog");
///CLOVER:OFF
/** stop instances being created **/
@ -48,6 +54,17 @@ public final class Utils
}
///CLOVER:ON
/**
* Accessor for shared instance of logger which should be
* used to log all exceptions occured during <code>FileSetCheck</code>
* work (<code>debug()</code> should be used).
* @return shared exception logger.
*/
public static Log getExceptionLogger()
{
return EXCEPTION_LOG;
}
/**
* Returns whether the specified string contains only whitespace up to the
* specified index.

View File

@ -27,6 +27,7 @@ import com.puppycrawl.tools.checkstyle.Defn;
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher;
import com.puppycrawl.tools.checkstyle.api.Utils;
import org.apache.commons.beanutils.ConversionException;
/**
@ -166,6 +167,7 @@ public class NewlineAtEndOfFileCheck
args,
this.getClass());
getMessageCollector().add(message);
Utils.getExceptionLogger().debug("IOException occured.", aEx);
}
///CLOVER:ON
}

View File

@ -35,6 +35,7 @@ import com.puppycrawl.tools.checkstyle.Defn;
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.api.MessageDispatcher;
import com.puppycrawl.tools.checkstyle.api.Utils;
/**
* <p>
@ -166,6 +167,7 @@ public class TranslationCheck
this.getClass());
final LocalizedMessage[] messages = new LocalizedMessage[] {message};
getMessageDispatcher().fireErrors(aFile.getPath(), messages);
Utils.getExceptionLogger().debug("IOException occured.", aEx);
}

View File

@ -127,6 +127,7 @@ public abstract class AbstractUsageCheck
public void logError(Exception aException)
{
log(0, "general.exception", new String[] {aException.getMessage()});
Utils.getExceptionLogger().debug("An exception occured.", aException);
}
/**