From 608eec242e872ff16dfdcaa0ac37c8ab8bca15c3 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 12 Jul 2010 08:44:52 +0000 Subject: [PATCH] added ignore to Logger interface git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2104 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../main/java/org/eclipse/jetty/util/log/JavaUtilLog.java | 8 ++++++++ .../src/main/java/org/eclipse/jetty/util/log/Log.java | 4 ++++ .../src/main/java/org/eclipse/jetty/util/log/Logger.java | 6 ++++++ .../main/java/org/eclipse/jetty/util/log/LoggerLog.java | 8 ++++++++ .../main/java/org/eclipse/jetty/util/log/Slf4jLog.java | 8 ++++++++ .../main/java/org/eclipse/jetty/util/log/StdErrLog.java | 8 ++++++++ 6 files changed, 42 insertions(+) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java index 19ecf110395..94d8e795dc1 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java @@ -114,6 +114,14 @@ public class JavaUtilLog implements Logger return new JavaUtilLog(name); } + public void ignore(Throwable ignored) + { + if (Log.isIgnored()) + { + warn(Log.IGNORED, ignored); + } + } + private String format(String msg, Object... args) { msg = String.valueOf(msg); // Avoids NPE diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java index 2adca111920..c050738f52e 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java @@ -116,6 +116,10 @@ public class Log return __log; } + static boolean isIgnored() + { + return __ignored; + } /** * Set Log to parent Logger. diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java index d96c04012aa..7fca765b02a 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java @@ -99,4 +99,10 @@ public interface Logger * @return a logger with the given name */ public Logger getLogger(String name); + + /** + * Ignore an exception. + *

This should be used rather than an empty catch block. + */ + public void ignore(Throwable ignored); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java index 6eef7bfa39e..3c2dc5f2826 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java @@ -181,6 +181,14 @@ public class LoggerLog implements Logger } } + public void ignore(Throwable ignored) + { + if (Log.isIgnored()) + { + warn(Log.IGNORED, ignored); + } + } + public Logger getLogger(String name) { try diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java index 7df5c9fd080..97cfec137ab 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java @@ -95,6 +95,14 @@ public class Slf4jLog implements Logger return new Slf4jLog(name); } + public void ignore(Throwable ignored) + { + if (Log.isIgnored()) + { + warn(Log.IGNORED, ignored); + } + } + @Override public String toString() { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java index 788bc081d81..88a63324f84 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java @@ -325,4 +325,12 @@ public class StdErrLog implements Logger { return "StdErrLog:" + _name + ":DEBUG=" + _debug; } + + public void ignore(Throwable ignored) + { + if (Log.isIgnored()) + { + warn(Log.IGNORED, ignored); + } + } }