Additional fix for #310603: Log cleanup.
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1592 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
1eba7b979a
commit
4eaf03f08e
|
@ -126,11 +126,8 @@ public class JavaUtilLog implements Logger
|
||||||
if (bracesIndex < 0)
|
if (bracesIndex < 0)
|
||||||
{
|
{
|
||||||
builder.append(msg.substring(start));
|
builder.append(msg.substring(start));
|
||||||
if (arg != null)
|
|
||||||
{
|
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
builder.append(arg);
|
builder.append(arg);
|
||||||
}
|
|
||||||
start = msg.length();
|
start = msg.length();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -12,16 +12,15 @@
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
|
|
||||||
package org.eclipse.jetty.util.log;
|
package org.eclipse.jetty.util.log;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.Loader;
|
import org.eclipse.jetty.util.Loader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logging.
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/** Logging.
|
|
||||||
* This class provides a static logging interface. If an instance of the
|
* This class provides a static logging interface. If an instance of the
|
||||||
* org.slf4j.Logger class is found on the classpath, the static log methods
|
* org.slf4j.Logger class is found on the classpath, the static log methods
|
||||||
* are directed to a slf4j logger for "org.eclipse.log". Otherwise the logs
|
* are directed to a slf4j logger for "org.eclipse.log". Otherwise the logs
|
||||||
|
@ -38,54 +37,47 @@ import org.eclipse.jetty.util.Loader;
|
||||||
*/
|
*/
|
||||||
public class Log
|
public class Log
|
||||||
{
|
{
|
||||||
private static final String[] __nestedEx =
|
|
||||||
{"getTargetException","getTargetError","getException","getRootCause"};
|
|
||||||
/*-------------------------------------------------------------------*/
|
|
||||||
private static final Class[] __noArgs=new Class[0];
|
|
||||||
public final static String EXCEPTION= "EXCEPTION ";
|
public final static String EXCEPTION= "EXCEPTION ";
|
||||||
public final static String IGNORED= "IGNORED";
|
public final static String IGNORED= "IGNORED";
|
||||||
public final static String IGNORED_FMT= "IGNORED: {}";
|
|
||||||
public final static String NOT_IMPLEMENTED= "NOT IMPLEMENTED ";
|
|
||||||
|
|
||||||
public static String __logClass;
|
public static String __logClass;
|
||||||
public static boolean __ignored;
|
public static boolean __ignored;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
AccessController.doPrivileged(new PrivilegedAction<Boolean>()
|
AccessController.doPrivileged(new PrivilegedAction<Object>()
|
||||||
{
|
{
|
||||||
public Boolean run()
|
public Object run()
|
||||||
{
|
{
|
||||||
__logClass = System.getProperty("org.eclipse.jetty.util.log.class","org.eclipse.jetty.util.log.Slf4jLog");
|
__logClass = System.getProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.Slf4jLog");
|
||||||
__ignored = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.log.IGNORED","false"));
|
__ignored = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.log.IGNORED", "false"));
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Logger __log;
|
private static Logger __log;
|
||||||
private static boolean _initialized;
|
private static boolean __initialized;
|
||||||
|
|
||||||
public static boolean initialized()
|
public static boolean initialized()
|
||||||
{
|
{
|
||||||
if (__log!=null)
|
if (__log != null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
synchronized (Log.class)
|
synchronized (Log.class)
|
||||||
{
|
{
|
||||||
if (_initialized)
|
if (__initialized)
|
||||||
return __log!=null;
|
return __log != null;
|
||||||
_initialized=true;
|
__initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class log_class=null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
log_class=Loader.loadClass(Log.class, __logClass);
|
Class log_class = Loader.loadClass(Log.class, __logClass);
|
||||||
if (__log==null || !__log.getClass().equals(log_class))
|
if (__log == null || !__log.getClass().equals(log_class))
|
||||||
{
|
{
|
||||||
__log=(Logger) log_class.newInstance();
|
__log = (Logger)log_class.newInstance();
|
||||||
__log.info("Logging to {} via {}",__log,log_class.getName());
|
__log.info("Logging to {} via {}", __log, log_class.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(NoClassDefFoundError e)
|
catch(NoClassDefFoundError e)
|
||||||
|
@ -97,7 +89,7 @@ public class Log
|
||||||
initStandardLogging(e);
|
initStandardLogging(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return __log!=null;
|
return __log != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initStandardLogging(Throwable e)
|
private static void initStandardLogging(Throwable e)
|
||||||
|
@ -105,17 +97,17 @@ public class Log
|
||||||
Class log_class;
|
Class log_class;
|
||||||
if(e != null && __ignored)
|
if(e != null && __ignored)
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (__log==null)
|
if (__log == null)
|
||||||
{
|
{
|
||||||
log_class= StdErrLog.class;
|
log_class = StdErrLog.class;
|
||||||
__log=new StdErrLog();
|
__log = new StdErrLog();
|
||||||
__log.info("Logging to {} via {}",__log,log_class.getName());
|
__log.info("Logging to {} via {}", __log, log_class.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLog(Logger log)
|
public static void setLog(Logger log)
|
||||||
{
|
{
|
||||||
Log.__log=log;
|
Log.__log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Logger getLog()
|
public static Logger getLog()
|
||||||
|
@ -148,63 +140,61 @@ public class Log
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class<?> uberlog = loader.getParent().loadClass("org.eclipse.jetty.util.log.Log");
|
Class<?> uberlog = loader.getParent().loadClass("org.eclipse.jetty.util.log.Log");
|
||||||
Method getLogger=uberlog.getMethod("getLogger",new Class[]{String.class});
|
Method getLogger = uberlog.getMethod("getLogger", new Class[]{String.class});
|
||||||
Object logger = getLogger.invoke(null,name);
|
Object logger = getLogger.invoke(null,name);
|
||||||
setLog(new LoggerLog(logger));
|
setLog(new LoggerLog(logger));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
setLog(getLogger(name));
|
setLog(getLogger(name));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void debug(Throwable th)
|
public static void debug(Throwable th)
|
||||||
{
|
{
|
||||||
if (!isDebugEnabled())
|
if (!isDebugEnabled())
|
||||||
return;
|
return;
|
||||||
__log.debug(EXCEPTION,th);
|
__log.debug(EXCEPTION, th);
|
||||||
unwind(th);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String msg)
|
public static void debug(String msg)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
|
__log.debug(msg);
|
||||||
__log.debug(msg,null,null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String msg,Object arg)
|
public static void debug(String msg, Object arg)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.debug(msg,arg,null);
|
__log.debug(msg, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String msg,Object arg0, Object arg1)
|
public static void debug(String msg, Object arg0, Object arg1)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.debug(msg,arg0,arg1);
|
__log.debug(msg, arg0, arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
|
||||||
/**
|
/**
|
||||||
* Ignore an exception unless trace is enabled.
|
* Ignore an exception unless trace is enabled.
|
||||||
* This works around the problem that log4j does not support the trace level.
|
* This works around the problem that log4j does not support the trace level.
|
||||||
|
* @param thrown the Throwable to ignore
|
||||||
*/
|
*/
|
||||||
public static void ignore(Throwable th)
|
public static void ignore(Throwable thrown)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
if (__ignored)
|
if (__ignored)
|
||||||
{
|
{
|
||||||
__log.warn(IGNORED,th);
|
__log.warn(IGNORED, thrown);
|
||||||
unwind(th);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,21 +202,21 @@ public class Log
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.info(msg,null,null);
|
__log.info(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(String msg,Object arg)
|
public static void info(String msg, Object arg)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.info(msg,arg,null);
|
__log.info(msg, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(String msg,Object arg0, Object arg1)
|
public static void info(String msg, Object arg0, Object arg1)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.info(msg,arg0,arg1);
|
__log.info(msg, arg0, arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDebugEnabled()
|
public static boolean isDebugEnabled()
|
||||||
|
@ -240,69 +230,47 @@ public class Log
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.warn(msg,null,null);
|
__log.warn(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(String msg,Object arg)
|
public static void warn(String msg, Object arg)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.warn(msg,arg,null);
|
__log.warn(msg, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(String msg,Object arg0, Object arg1)
|
public static void warn(String msg, Object arg0, Object arg1)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.warn(msg,arg0,arg1);
|
__log.warn(msg, arg0, arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(String msg, Throwable th)
|
public static void warn(String msg, Throwable th)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.warn(msg,th);
|
__log.warn(msg, th);
|
||||||
unwind(th);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warn(Throwable th)
|
public static void warn(Throwable th)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return;
|
return;
|
||||||
__log.warn(EXCEPTION,th);
|
__log.warn(EXCEPTION, th);
|
||||||
unwind(th);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Obtain a named Logger.
|
/**
|
||||||
* Obtain a named Logger or the default Logger if null is passed.
|
* Obtain a named Logger or the default Logger if null is passed.
|
||||||
|
* @param name the Logger name
|
||||||
|
* @return the Logger with the given name
|
||||||
*/
|
*/
|
||||||
public static Logger getLogger(String name)
|
public static Logger getLogger(String name)
|
||||||
{
|
{
|
||||||
if (!initialized())
|
if (!initialized())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (name==null)
|
return name == null ? __log : __log.getLogger(name);
|
||||||
return __log;
|
|
||||||
return __log.getLogger(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void unwind(Throwable th)
|
|
||||||
{
|
|
||||||
if (th==null)
|
|
||||||
return;
|
|
||||||
for (int i=0;i<__nestedEx.length;i++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Method get_target = th.getClass().getMethod(__nestedEx[i],__noArgs);
|
|
||||||
Throwable th2=(Throwable)get_target.invoke(th,(Object[])null);
|
|
||||||
if (th2!=null && th2!=th)
|
|
||||||
warn("Nested in "+th+":",th2);
|
|
||||||
}
|
|
||||||
catch(Exception ignore){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,11 +197,8 @@ public class StdErrLog implements Logger
|
||||||
if (bracesIndex < 0)
|
if (bracesIndex < 0)
|
||||||
{
|
{
|
||||||
escape(builder, msg.substring(start));
|
escape(builder, msg.substring(start));
|
||||||
if (arg != null)
|
|
||||||
{
|
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
builder.append(arg);
|
builder.append(arg);
|
||||||
}
|
|
||||||
start = msg.length();
|
start = msg.length();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue