Fixes 310603 (Make Logger interface consistent).

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1570 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Simone Bordet 2010-04-27 11:04:59 +00:00
parent 19f96a84ed
commit 19368f3985
6 changed files with 408 additions and 430 deletions

View File

@ -21,6 +21,7 @@ jetty-7.1.0-SNAPSHOT
+ Fix jetty-plus.xml reference to addLifeCycle
+ Add AnnotationConfiguration to jetty-plus.xml
+ 310467 Allow SocketConnector to create generic Connection objects
+ 310603 Make Logger interface consistent
jetty-7.0.2.v20100331 31 March 2010
+ 297552 Don't call Continuation timeouts from acceptor tick

View File

@ -22,12 +22,12 @@ import java.util.logging.Level;
* <p>
* Implementation of Jetty {@link Logger} based on {@link java.util.logging.Logger}.
* </p>
*
*
* <p>
* Honors the standard jetty system property <code>"org.eclipse.jetty.util.log.DEBUG"</code> to set logger into debug
* mode (defaults to false, set to "true" to enable)
* </p>
*
*
* <p>
* You can also set the logger level using <a href="http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html">
* standard java.util.logging configuration</a> against the name <code>"org.eclipse.jetty.util.log"</code>.
@ -46,44 +46,42 @@ public class JavaUtilLog implements Logger
{
_logger = java.util.logging.Logger.getLogger(name);
if (Boolean.getBoolean("org.eclipse.jetty.util.log.DEBUG"))
{
_logger.setLevel(Level.FINE);
}
}
public String getName()
{
return _logger.getName();
}
public void debug(String msg)
public void warn(String msg, Object... args)
{
_logger.log(Level.FINE,msg);
_logger.log(Level.WARNING, format(msg, args));
}
public void debug(String msg, Throwable th)
public void warn(Throwable thrown)
{
_logger.log(Level.FINE,msg,th);
warn("", thrown);
}
public void debug(String msg, Object arg0, Object arg1)
public void warn(String msg, Throwable thrown)
{
_logger.log(Level.FINE,format(msg,arg0,arg1));
_logger.log(Level.WARNING, msg, thrown);
}
public Logger getLogger(String name)
public void info(String msg, Object... args)
{
return new JavaUtilLog(name);
_logger.log(Level.INFO, format(msg, args));
}
public void info(String msg)
public void info(Throwable thrown)
{
_logger.log(Level.INFO,msg);
info("", thrown);
}
public void info(String msg, Object arg0, Object arg1)
public void info(String msg, Throwable thrown)
{
_logger.log(Level.INFO,format(msg,arg0,arg1));
_logger.log(Level.INFO, msg, thrown);
}
public boolean isDebugEnabled()
@ -96,30 +94,42 @@ public class JavaUtilLog implements Logger
_logger.setLevel(Level.FINE);
}
public void warn(String msg)
public void debug(String msg, Object... args)
{
_logger.log(Level.WARNING,msg);
_logger.log(Level.FINE, format(msg, args));
}
public void warn(String msg, Object arg0, Object arg1)
public void debug(Throwable thrown)
{
_logger.log(Level.WARNING,format(msg,arg0,arg1));
debug("", thrown);
}
public void warn(String msg, Throwable th)
public void debug(String msg, Throwable thrown)
{
_logger.log(Level.WARNING,msg,th);
_logger.log(Level.FINE, msg, thrown);
}
private String format(String msg, Object arg0, Object arg1)
public Logger getLogger(String name)
{
int i0 = msg.indexOf("{}");
int i1 = i0 < 0?-1:msg.indexOf("{}",i0 + 2);
return new JavaUtilLog(name);
}
if (arg1 != null && i1 >= 0)
msg = msg.substring(0,i1) + arg1 + msg.substring(i1 + 2);
if (arg0 != null && i0 >= 0)
msg = msg.substring(0,i0) + arg0 + msg.substring(i0 + 2);
return msg;
private String format(String msg, Object... args)
{
msg = String.valueOf(msg); // Avoids NPE
String braces = "{}";
StringBuilder builder = new StringBuilder();
int start = 0;
for (Object arg : args)
{
int bracesIndex = msg.indexOf(braces, start);
if (bracesIndex < 0)
break;
builder.append(msg.substring(start, bracesIndex));
builder.append(String.valueOf(arg));
start = bracesIndex + braces.length();
}
builder.append(msg.substring(start));
return builder.toString();
}
}

View File

@ -4,39 +4,102 @@
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.log;
/** Logging Facade
* A simple logging facade that is intended simply to capture the style
* of logging as used by Jetty.
*
/**
* A simple logging facade that is intended simply to capture the style of logging as used by Jetty.
*/
public interface Logger
{
/**
* @return the name of this logger
*/
public String getName();
/**
* Formats and logs at warn level.
* @param msg the formatting string
* @param arg the first argument
* @param args the optional arguments
*/
public void warn(String msg, Object... args);
/**
* Logs the given Throwable information at warn level
* @param thrown the Throwable to log
*/
public void warn(Throwable thrown);
/**
* Logs the given message at warn level, with Throwable information.
* @param msg the message to log
* @param thrown the Throwable to log
*/
public void warn(String msg, Throwable thrown);
/**
* Formats and logs at info level.
* @param msg the formatting string
* @param arg the first argument
* @param args the optional arguments
*/
public void info(String msg, Object... args);
/**
* Logs the given Throwable information at info level
* @param thrown the Throwable to log
*/
public void info(Throwable thrown);
/**
* Logs the given message at info level, with Throwable information.
* @param msg the message to log
* @param thrown the Throwable to log
*/
public void info(String msg, Throwable thrown);
/**
* @return whether the debug level is enabled
*/
public boolean isDebugEnabled();
/** Mutator used to turn debug on programatically.
* Implementations operation in which case an appropriate
* warning message shall be generated.
/**
* Mutator used to turn debug on programmatically.
* @param enabled whether to enable the debug level
*/
public void setDebugEnabled(boolean enabled);
public void info(String msg);
public void info(String msg,Object arg0, Object arg1);
public void debug(String msg);
public void debug(String msg,Throwable th);
public void debug(String msg,Object arg0, Object arg1);
public void warn(String msg);
public void warn(String msg,Object arg0, Object arg1);
public void warn(String msg, Throwable th);
/**
* Formats and logs at debug level.
* @param msg the formatting string
* @param arg the first argument
* @param args the optional arguments
*/
public void debug(String msg, Object... args);
/**
* Logs the given Throwable information at debug level
* @param thrown the Throwable to log
*/
public void debug(Throwable thrown);
/**
* Logs the given message at debug level, with Throwable information.
* @param msg the message to log
* @param thrown the Throwable to log
*/
public void debug(String msg, Throwable thrown);
/**
* @param name the name of the logger
* @return a logger with the given name
*/
public Logger getLogger(String name);
public String getName();
}

View File

@ -4,124 +4,77 @@
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.log;
import java.lang.reflect.Method;
/**
*
*/
public class LoggerLog implements Logger
{
boolean _debug;
Object _logger;
Method _debugMT;
Method _debugMAA;
Method _infoMAA;
Method _warnMT;
Method _warnMAA;
Method _isDebugEnabled;
Method _setDebugEnabledE;
Method _getLoggerN;
private final Object _logger;
private final Method _debugMT;
private final Method _debugMAA;
private final Method _infoMT;
private final Method _infoMAA;
private final Method _warnMT;
private final Method _warnMAA;
private final Method _setDebugEnabledE;
private final Method _getLoggerN;
private final Method _getName;
private volatile boolean _debug;
public LoggerLog(Object logger)
{
try
{
_logger=logger;
Class<?> lc=logger.getClass();
_debugMT=lc.getMethod("debug",new Class[]{String.class,Throwable.class});
_debugMAA=lc.getMethod("debug",new Class[]{String.class,Object.class,Object.class});
_infoMAA=lc.getMethod("info",new Class[]{String.class,Object.class,Object.class});
_warnMT=lc.getMethod("warn",new Class[]{String.class,Throwable.class});
_warnMAA=lc.getMethod("warn",new Class[]{String.class,Object.class,Object.class});
_isDebugEnabled=lc.getMethod("isDebugEnabled",new Class[]{});
_setDebugEnabledE=lc.getMethod("setDebugEnabled",new Class[]{Boolean.TYPE});
_getLoggerN=lc.getMethod("getLogger",new Class[]{String.class});
_debug=((Boolean)_isDebugEnabled.invoke(_logger,(Object[])null)).booleanValue();
_logger = logger;
Class<?> lc = logger.getClass();
_debugMT = lc.getMethod("debug", new Class[]{String.class, Throwable.class});
_debugMAA = lc.getMethod("debug", new Class[]{String.class, Object[].class});
_infoMT = lc.getMethod("info", new Class[]{String.class, Throwable.class});
_infoMAA = lc.getMethod("info", new Class[]{String.class, Object[].class});
_warnMT = lc.getMethod("warn", new Class[]{String.class, Throwable.class});
_warnMAA = lc.getMethod("warn", new Class[]{String.class, Object[].class});
Method _isDebugEnabled = lc.getMethod("isDebugEnabled");
_setDebugEnabledE = lc.getMethod("setDebugEnabled", new Class[]{Boolean.TYPE});
_getLoggerN = lc.getMethod("getLogger", new Class[]{String.class});
_getName = lc.getMethod("getName");
_debug = (Boolean)_isDebugEnabled.invoke(_logger);
}
catch(Exception e)
catch(Exception x)
{
e.printStackTrace();
throw new IllegalStateException(e);
throw new IllegalStateException(x);
}
}
public String getName()
{
return _logger.toString();
}
public void debug(String msg, Throwable th)
{
if (_debug)
{
try
{
_debugMT.invoke(_logger,msg,th);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public void debug(String msg)
{
if (_debug)
{
try
{
_debugMAA.invoke(_logger,msg,null,null);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public void debug(String msg, Object arg0, Object arg1)
{
if (_debug)
{
try
{
_debugMAA.invoke(_logger,msg,arg0,arg1);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public Logger getLogger(String name)
{
try
{
Object logger=_getLoggerN.invoke(_logger,name);
return new LoggerLog(logger);
return (String)_getName.invoke(_logger);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return this;
}
public void info(String msg)
public void warn(String msg, Object... args)
{
try
{
_infoMAA.invoke(_logger,msg,null,null);
_warnMAA.invoke(_logger, args);
}
catch (Exception e)
{
@ -129,11 +82,45 @@ public class LoggerLog implements Logger
}
}
public void info(String msg, Object arg0, Object arg1)
public void warn(Throwable thrown)
{
warn("", thrown);
}
public void warn(String msg, Throwable thrown)
{
try
{
_infoMAA.invoke(_logger,msg,arg0,arg1);
_warnMT.invoke(_logger, msg, thrown);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void info(String msg, Object... args)
{
try
{
_infoMAA.invoke(_logger, args);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void info(Throwable thrown)
{
info("", thrown);
}
public void info(String msg, Throwable thrown)
{
try
{
_infoMT.invoke(_logger, msg, thrown);
}
catch (Exception e)
{
@ -150,50 +137,61 @@ public class LoggerLog implements Logger
{
try
{
_setDebugEnabledE.invoke(_logger,enabled);
_debug=enabled;
_setDebugEnabledE.invoke(_logger, enabled);
_debug = enabled;
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void warn(String msg)
public void debug(String msg, Object... args)
{
if (!_debug)
return;
try
{
_debugMAA.invoke(_logger, args);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void debug(Throwable thrown)
{
debug("", thrown);
}
public void debug(String msg, Throwable th)
{
if (!_debug)
return;
try
{
_debugMT.invoke(_logger, msg, th);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public Logger getLogger(String name)
{
try
{
_warnMAA.invoke(_logger,msg,null,null);
Object logger=_getLoggerN.invoke(_logger, name);
return new LoggerLog(logger);
}
catch (Exception e)
{
e.printStackTrace();
return this;
}
}
public void warn(String msg, Object arg0, Object arg1)
{
try
{
_warnMAA.invoke(_logger,msg,arg0,arg1);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void warn(String msg, Throwable th)
{
try
{
_warnMT.invoke(_logger,msg,th);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

View File

@ -4,144 +4,100 @@
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.log;
/* ------------------------------------------------------------ */
/** Slf4jLog Logger
*
/**
* Slf4jLog Logger
*/
public class Slf4jLog implements Logger
{
private org.slf4j.Logger _logger;
private final org.slf4j.Logger _logger;
public Slf4jLog() throws Exception
{
this("org.eclipse.jetty.util.log");
}
public Slf4jLog(String name)
{
_logger = org.slf4j.LoggerFactory.getLogger( name );
}
public String getName()
{
return _logger.getName();
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doDebug(java.lang.String)
*/
public void debug(String msg)
public void warn(String msg, Object... args)
{
_logger.debug(msg);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doDebug(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void debug(String msg, Object arg0, Object arg1)
{
_logger.debug(msg, arg0, arg1);
_logger.warn(msg, args);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doDebug(java.lang.String, java.lang.Throwable)
*/
public void debug(String msg, Throwable th)
public void warn(Throwable thrown)
{
_logger.debug(msg, th);
warn("", thrown);
}
public void warn(String msg, Throwable thrown)
{
_logger.warn(msg, thrown);
}
public void info(String msg, Object... args)
{
_logger.info(msg, args);
}
public void info(Throwable thrown)
{
info("", thrown);
}
public void info(String msg, Throwable thrown)
{
_logger.info(msg, thrown);
}
public void debug(String msg, Object... args)
{
_logger.debug(msg, args);
}
public void debug(Throwable thrown)
{
debug("", thrown);
}
public void debug(String msg, Throwable thrown)
{
_logger.debug(msg, thrown);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doDebugEnabled()
*/
public boolean isDebugEnabled()
{
return _logger.isDebugEnabled();
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doInfo(java.lang.String)
*/
public void info(String msg)
public void setDebugEnabled(boolean enabled)
{
_logger.info(msg);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doInfo(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void info(String msg, Object arg0, Object arg1)
{
_logger.info(msg, arg0, arg1);
warn("setDebugEnabled not implemented",null,null);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doWarn(java.lang.String)
*/
public void warn(String msg)
{
_logger.warn(msg);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doWarn(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void warn(String msg, Object arg0, Object arg1)
{
_logger.warn(msg, arg0, arg1);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.log.Log#doWarn(java.lang.String, java.lang.Throwable)
*/
public void warn(String msg, Throwable th)
{
if (th instanceof RuntimeException || th instanceof Error)
_logger.error(msg, th);
else
_logger.warn(msg,th);
}
/* ------------------------------------------------------------ */
public Logger getLogger(String name)
{
return new Slf4jLog(name);
}
/* ------------------------------------------------------------ */
@Override
public String toString()
{
return _logger.toString();
}
/* ------------------------------------------------------------ */
public void setDebugEnabled(boolean enabled)
{
warn("setDebugEnabled not implemented",null,null);
}
}

View File

@ -4,11 +4,11 @@
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.log;
@ -17,28 +17,23 @@ import java.security.AccessControlException;
import org.eclipse.jetty.util.DateCache;
/*-----------------------------------------------------------------------*/
/**
* StdErr Logging. This implementation of the Logging facade sends all logs to
* StdErr with minimal formatting.
*
*
* If the system property "org.eclipse.jetty.util.log.DEBUG" is set, then debug
* logs are printed if stderr is being used.
* <p>
* For named debuggers, the system property name+".DEBUG" is checked. If it is
* not not set, then "org.eclipse.jetty.util.log.DEBUG" is used as the default.
*
*/
public class StdErrLog implements Logger
{
private static DateCache _dateCache;
private final static String LN = System.getProperty("line.separator");
private final static boolean __debug = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.log.DEBUG",System.getProperty(
"org.eclipse.jetty.util.log.stderr.DEBUG","false")));
private boolean _debug = __debug;
private final String _name;
private boolean _hideStacks = false;
private final static boolean __debug = Boolean.parseBoolean(
System.getProperty("org.eclipse.jetty.util.log.DEBUG",
System.getProperty("org.eclipse.jetty.util.log.stderr.DEBUG", "false")));
static
{
@ -46,13 +41,16 @@ public class StdErrLog implements Logger
{
_dateCache = new DateCache("yyyy-MM-dd HH:mm:ss");
}
catch (Exception e)
catch (Exception x)
{
e.printStackTrace();
x.printStackTrace();
}
}
private boolean _debug = __debug;
private final String _name;
private boolean _hideStacks = false;
public StdErrLog()
{
this(null);
@ -60,11 +58,11 @@ public class StdErrLog implements Logger
public StdErrLog(String name)
{
this._name = name == null?"":name;
this._name = name == null ? "" : name;
try
{
_debug = Boolean.parseBoolean(System.getProperty(_name + ".DEBUG",Boolean.toString(__debug)));
_debug = Boolean.parseBoolean(System.getProperty(_name + ".DEBUG", Boolean.toString(__debug)));
}
catch (AccessControlException ace)
{
@ -77,16 +75,6 @@ public class StdErrLog implements Logger
return _name;
}
public boolean isDebugEnabled()
{
return _debug;
}
public void setDebugEnabled(boolean enabled)
{
_debug = enabled;
}
public boolean isHideStacks()
{
return _hideStacks;
@ -97,104 +85,92 @@ public class StdErrLog implements Logger
_hideStacks = hideStacks;
}
public void info(String msg)
public void warn(String msg, Object... args)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":INFO:");
format(buffer, msg);
System.err.println(buffer);
}
public void info(String msg, Object arg0, Object arg1)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":INFO:");
format(buffer,msg,arg0, arg1);
System.err.println(buffer);
}
public void debug(String msg, Throwable th)
{
if (_debug)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":DBUG:");
format(buffer, msg);
if (_hideStacks)
format(buffer, String.valueOf(th));
else
format(th, buffer);
System.err.println(buffer);
}
}
public void debug(String msg)
{
if (_debug)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":DBUG:");
format(buffer, msg);
System.err.println(buffer);
}
}
public void debug(String msg, Object arg0, Object arg1)
{
if (_debug)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":DBUG:");
format(buffer,msg,arg0, arg1);
System.err.println(buffer);
}
}
public void warn(String msg)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":WARN:");
format(buffer, msg);
format(buffer, ":WARN:", msg, args);
System.err.println(buffer);
}
public void warn(String msg, Object arg0, Object arg1)
public void warn(Throwable thrown)
{
warn("", thrown);
}
public void warn(String msg, Throwable thrown)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":WARN:");
format(buffer,msg,arg0, arg1);
format(buffer, ":WARN:", msg, thrown);
System.err.println(buffer);
}
public void warn(String msg, Throwable th)
public void info(String msg, Object... args)
{
StringBuilder buffer = new StringBuilder(64);
format(buffer, ":INFO:", msg, args);
System.err.println(buffer);
}
public void info(Throwable thrown)
{
info("", thrown);
}
public void info(String msg, Throwable thrown)
{
StringBuilder buffer = new StringBuilder(64);
format(buffer, ":INFO:", msg, thrown);
System.err.println(buffer);
}
public boolean isDebugEnabled()
{
return _debug;
}
public void setDebugEnabled(boolean enabled)
{
_debug = enabled;
}
public void debug(String msg, Object... args)
{
if (!_debug)
return;
StringBuilder buffer = new StringBuilder(64);
format(buffer, ":DBUG:", msg, args);
System.err.println(buffer);
}
public void debug(Throwable thrown)
{
debug("", thrown);
}
public void debug(String msg, Throwable thrown)
{
if (!_debug)
return;
StringBuilder buffer = new StringBuilder(64);
format(buffer, ":INFO:", msg, thrown);
System.err.println(buffer);
}
private void format(StringBuilder buffer, String level, String msg, Object... args)
{
String d = _dateCache.now();
int ms = _dateCache.lastMs();
StringBuilder buffer = new StringBuilder(64);
tag(buffer,d,ms, ":WARN:");
format(buffer, msg);
if (_hideStacks)
format(buffer, String.valueOf(th));
tag(buffer, d, ms, level);
format(buffer, msg, args);
}
private void format(StringBuilder buffer, String level, String msg, Throwable thrown)
{
format(buffer, level, msg);
if (isHideStacks())
format(buffer, String.valueOf(thrown));
else
format(th, buffer);
System.err.println(buffer);
format(buffer, thrown);
}
private void tag(StringBuilder buffer, String d, int ms, String tag)
@ -210,79 +186,53 @@ public class StdErrLog implements Logger
buffer.append(ms).append(tag).append(_name).append(':');
}
private void format(StringBuilder buffer, String msg, Object arg0, Object arg1)
private void format(StringBuilder builder, String msg, Object... args)
{
int i0 = msg == null?-1:msg.indexOf("{}");
int i1 = i0 < 0?-1:msg.indexOf("{}",i0 + 2);
if (i0 >= 0)
msg = String.valueOf(msg); // Avoids NPE
String braces = "{}";
int start = 0;
for (Object arg : args)
{
format(buffer, msg.substring(0,i0));
format(buffer, String.valueOf(arg0 == null?"null":arg0));
int bracesIndex = msg.indexOf(braces, start);
if (bracesIndex < 0)
break;
escape(builder, msg.substring(start, bracesIndex));
builder.append(String.valueOf(arg));
start = bracesIndex + braces.length();
}
escape(builder, msg.substring(start));
}
if (i1 >= 0)
private void escape(StringBuilder builder, String string)
{
for (int i = 0; i < string.length(); ++i)
{
char c = string.charAt(i);
if (Character.isISOControl(c))
{
format(buffer, msg.substring(i0 + 2,i1));
format(buffer, String.valueOf(arg1 == null?"null":arg1));
format(buffer, msg.substring(i1 + 2));
if (c == '\n')
builder.append('|');
else if (c == '\r')
builder.append('<');
else
builder.append('?');
}
else
{
format(buffer, msg.substring(i0 + 2));
if (arg1 != null)
{
buffer.append(' ');
format(buffer, String.valueOf(arg1));
}
}
builder.append(c);
}
else
}
private void format(StringBuilder buffer, Throwable thrown)
{
if (thrown == null)
{
format(buffer, msg);
if (arg0 != null)
{
buffer.append(' ');
format(buffer, String.valueOf(arg0));
}
if (arg1 != null)
{
buffer.append(' ');
format(buffer, String.valueOf(arg1));
}
buffer.append("null");
}
}
private void format(StringBuilder buffer, String msg)
{
if (msg == null)
buffer.append("null");
else
for (int i = 0; i < msg.length(); i++)
{
char c = msg.charAt(i);
if (Character.isISOControl(c))
{
if (c == '\n')
buffer.append('|');
else if (c == '\r')
buffer.append('<');
else
buffer.append('?');
}
else
buffer.append(c);
}
}
private void format(Throwable th, StringBuilder buffer)
{
if (th == null)
buffer.append("null");
else
{
buffer.append('\n');
format(buffer, th.toString());
StackTraceElement[] elements = th.getStackTrace();
format(buffer, thrown.toString());
StackTraceElement[] elements = thrown.getStackTrace();
for (int i = 0; elements != null && i < elements.length; i++)
{
buffer.append("\n\tat ");