311362 Optional org.eclipse.jetty.util.log.stderr.SOURCE

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1647 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-05-03 13:15:49 +00:00
parent 5662d548f6
commit 820855b3b5
2 changed files with 64 additions and 6 deletions

View File

@ -15,6 +15,7 @@ jetty-7.1.0.RC1-SNAPSHOT
+ 311154 Use Appendable in preference to StringBuilder/StringBuffer in APIs
+ 308865 Update test suite to JUnit4 - Module jetty-start
+ 309153 Hide extracted WEB-INF/lib when running a non-extracted war
+ 311362 Optional org.eclipse.jetty.util.log.stderr.SOURCE
jetty-7.1.0.RC0 27 April 2010
+ 294563 Websocket client connection

View File

@ -20,12 +20,17 @@ 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.
* If the system property "org.eclipse.jetty.util.log.DEBUG" is set, then debug
* logs are printed if stderr is being used. 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.
* <p>
* If the system property "org.eclipse.jetty.util.log.SOURCE" is set, then the
* source method/file of a log is logged. For named debuggers, the system
* property name+".SOURCE" is checked. If it is not not set, then
* "org.eclipse.jetty.util.log.SOURCE" is used as the default.
*
*/
public class StdErrLog implements Logger
{
@ -34,6 +39,9 @@ public class StdErrLog implements Logger
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 final static boolean __source = Boolean.parseBoolean(
System.getProperty("org.eclipse.jetty.util.log.SOURCE",
System.getProperty("org.eclipse.jetty.util.log.stderr.SOURCE", "false")));
static
{
@ -48,6 +56,7 @@ public class StdErrLog implements Logger
}
private boolean _debug = __debug;
private boolean _source = __source;
private final String _name;
private boolean _hideStacks = false;
@ -62,12 +71,21 @@ public class StdErrLog implements Logger
try
{
_debug = Boolean.parseBoolean(System.getProperty(_name + ".DEBUG", Boolean.toString(__debug)));
_debug = Boolean.parseBoolean(System.getProperty(_name + ".DEBUG", Boolean.toString(_debug)));
}
catch (AccessControlException ace)
{
_debug = __debug;
}
try
{
_source = Boolean.parseBoolean(System.getProperty(_name + ".SOURCE", Boolean.toString(_source)));
}
catch (AccessControlException ace)
{
_source = __source;
}
}
public String getName()
@ -85,6 +103,24 @@ public class StdErrLog implements Logger
_hideStacks = hideStacks;
}
/* ------------------------------------------------------------ */
/** Is the source of a log, logged
* @return true if the class, method, file and line number of a log is logged.
*/
public boolean isSource()
{
return _source;
}
/* ------------------------------------------------------------ */
/** Set if a log source is logged.
* @param source true if the class, method, file and line number of a log is logged.
*/
public void setSource(boolean source)
{
_source = source;
}
public void warn(String msg, Object... args)
{
StringBuilder buffer = new StringBuilder(64);
@ -184,6 +220,27 @@ public class StdErrLog implements Logger
else
buffer.append(".00");
buffer.append(ms).append(tag).append(_name).append(':');
if (_source)
{
Throwable source = new Throwable();
StackTraceElement[] frames = source.getStackTrace();
for (int i=0;i<frames.length;i++)
{
final StackTraceElement frame = frames[i];
String clazz = frame.getClassName();
if (clazz.equals(StdErrLog.class.getName())|| clazz.equals(Log.class.getName()))
continue;
if (clazz.startsWith("org.eclipse.jetty."))
buffer.append("o.e.j.").append(clazz,18,clazz.length());
else
buffer.append(clazz);
buffer.append('#').append(frame.getMethodName());
if (frame.getFileName()!=null)
buffer.append('(').append(frame.getFileName()).append(':').append(frame.getLineNumber()).append(')');
buffer.append(':');
break;
}
}
}
private void format(StringBuilder builder, String msg, Object... args)