276670 SLF4J loggers show correct location information

This commit is contained in:
Michael Gorovoy 2011-08-16 16:23:41 -04:00
parent faaeabd243
commit fa7364ac1b
3 changed files with 618 additions and 3 deletions

View File

@ -0,0 +1,593 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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
// 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.
// ========================================================================
package org.eclipse.jetty.util.log;
import org.slf4j.Marker;
/* ------------------------------------------------------------ */
class JettyAwareLogger implements org.slf4j.Logger
{
private static final int DEBUG = org.slf4j.spi.LocationAwareLogger.DEBUG_INT;
private static final int ERROR = org.slf4j.spi.LocationAwareLogger.ERROR_INT;
private static final int INFO = org.slf4j.spi.LocationAwareLogger.INFO_INT;
private static final int TRACE = org.slf4j.spi.LocationAwareLogger.TRACE_INT;
private static final int WARN = org.slf4j.spi.LocationAwareLogger.WARN_INT;
private final org.slf4j.spi.LocationAwareLogger _logger;
public JettyAwareLogger(org.slf4j.spi.LocationAwareLogger logger)
{
_logger = logger;
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#getName()
*/
public String getName()
{
return _logger.getName();
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isTraceEnabled()
*/
public boolean isTraceEnabled()
{
return _logger.isTraceEnabled();
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(java.lang.String)
*/
public void trace(String msg)
{
log(null, TRACE, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object)
*/
public void trace(String format, Object arg)
{
log(null, TRACE, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void trace(String format, Object arg1, Object arg2)
{
log(null, TRACE, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object[])
*/
public void trace(String format, Object[] argArray)
{
log(null, TRACE, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(java.lang.String, java.lang.Throwable)
*/
public void trace(String msg, Throwable t)
{
log(null, TRACE, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isTraceEnabled(org.slf4j.Marker)
*/
public boolean isTraceEnabled(Marker marker)
{
return _logger.isTraceEnabled(marker);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String)
*/
public void trace(Marker marker, String msg)
{
log(marker, TRACE, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Object)
*/
public void trace(Marker marker, String format, Object arg)
{
log(marker, TRACE, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
*/
public void trace(Marker marker, String format, Object arg1, Object arg2)
{
log(marker, TRACE, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Object[])
*/
public void trace(Marker marker, String format, Object[] argArray)
{
log(marker, TRACE, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
*/
public void trace(Marker marker, String msg, Throwable t)
{
log(marker, TRACE, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isDebugEnabled()
*/
public boolean isDebugEnabled()
{
return _logger.isDebugEnabled();
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(java.lang.String)
*/
public void debug(String msg)
{
log(null, DEBUG, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object)
*/
public void debug(String format, Object arg)
{
log(null, DEBUG, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void debug(String format, Object arg1, Object arg2)
{
log(null, DEBUG, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object[])
*/
public void debug(String format, Object[] argArray)
{
log(null, DEBUG, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(java.lang.String, java.lang.Throwable)
*/
public void debug(String msg, Throwable t)
{
log(null, DEBUG, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isDebugEnabled(org.slf4j.Marker)
*/
public boolean isDebugEnabled(Marker marker)
{
return _logger.isDebugEnabled(marker);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String)
*/
public void debug(Marker marker, String msg)
{
log(marker, DEBUG, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Object)
*/
public void debug(Marker marker, String format, Object arg)
{
log(marker, DEBUG, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
*/
public void debug(Marker marker, String format, Object arg1, Object arg2)
{
log(marker, DEBUG, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Object[])
*/
public void debug(Marker marker, String format, Object[] argArray)
{
log(marker, DEBUG, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
*/
public void debug(Marker marker, String msg, Throwable t)
{
log(marker, DEBUG, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isInfoEnabled()
*/
public boolean isInfoEnabled()
{
return _logger.isInfoEnabled();
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(java.lang.String)
*/
public void info(String msg)
{
log(null, INFO, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(java.lang.String, java.lang.Object)
*/
public void info(String format, Object arg)
{
log(null, INFO, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void info(String format, Object arg1, Object arg2)
{
log(null, INFO, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(java.lang.String, java.lang.Object[])
*/
public void info(String format, Object[] argArray)
{
log(null, INFO, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(java.lang.String, java.lang.Throwable)
*/
public void info(String msg, Throwable t)
{
log(null, INFO, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isInfoEnabled(org.slf4j.Marker)
*/
public boolean isInfoEnabled(Marker marker)
{
return _logger.isInfoEnabled(marker);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String)
*/
public void info(Marker marker, String msg)
{
log(marker, INFO, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Object)
*/
public void info(Marker marker, String format, Object arg)
{
log(marker, INFO, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
*/
public void info(Marker marker, String format, Object arg1, Object arg2)
{
log(marker, INFO, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Object[])
*/
public void info(Marker marker, String format, Object[] argArray)
{
log(marker, INFO, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
*/
public void info(Marker marker, String msg, Throwable t)
{
log(marker, INFO, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isWarnEnabled()
*/
public boolean isWarnEnabled()
{
return _logger.isWarnEnabled();
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(java.lang.String)
*/
public void warn(String msg)
{
log(null, WARN, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object)
*/
public void warn(String format, Object arg)
{
log(null, WARN, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object[])
*/
public void warn(String format, Object[] argArray)
{
log(null, WARN, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void warn(String format, Object arg1, Object arg2)
{
log(null, WARN, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(java.lang.String, java.lang.Throwable)
*/
public void warn(String msg, Throwable t)
{
log(null, WARN, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isWarnEnabled(org.slf4j.Marker)
*/
public boolean isWarnEnabled(Marker marker)
{
return _logger.isWarnEnabled(marker);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String)
*/
public void warn(Marker marker, String msg)
{
log(marker, WARN, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Object)
*/
public void warn(Marker marker, String format, Object arg)
{
log(marker, WARN, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
*/
public void warn(Marker marker, String format, Object arg1, Object arg2)
{
log(marker, WARN, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Object[])
*/
public void warn(Marker marker, String format, Object[] argArray)
{
log(marker, WARN, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
*/
public void warn(Marker marker, String msg, Throwable t)
{
log(marker, WARN, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isErrorEnabled()
*/
public boolean isErrorEnabled()
{
return _logger.isErrorEnabled();
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(java.lang.String)
*/
public void error(String msg)
{
log(null, ERROR, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(java.lang.String, java.lang.Object)
*/
public void error(String format, Object arg)
{
log(null, ERROR, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(java.lang.String, java.lang.Object, java.lang.Object)
*/
public void error(String format, Object arg1, Object arg2)
{
log(null, ERROR, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(java.lang.String, java.lang.Object[])
*/
public void error(String format, Object[] argArray)
{
log(null, ERROR, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(java.lang.String, java.lang.Throwable)
*/
public void error(String msg, Throwable t)
{
log(null, ERROR, msg, null, t);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#isErrorEnabled(org.slf4j.Marker)
*/
public boolean isErrorEnabled(Marker marker)
{
return _logger.isErrorEnabled(marker);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String)
*/
public void error(Marker marker, String msg)
{
log(marker, ERROR, msg, null, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Object)
*/
public void error(Marker marker, String format, Object arg)
{
log(marker, ERROR, format, new Object[]{arg}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
*/
public void error(Marker marker, String format, Object arg1, Object arg2)
{
log(marker, ERROR, format, new Object[]{arg1,arg2}, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Object[])
*/
public void error(Marker marker, String format, Object[] argArray)
{
log(marker, ERROR, format, argArray, null);
}
/* ------------------------------------------------------------ */
/**
* @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
*/
public void error(Marker marker, String msg, Throwable t)
{
log(marker, ERROR, msg, null, t);
}
@Override
public String toString()
{
return _logger.toString();
}
private void log(Marker marker, int level, String msg, Object[] objArray, Throwable t)
{
_logger.log(marker,"org.eclipse.jetty.util.log.Log",level, msg, objArray,t);
}
}

View File

@ -13,6 +13,8 @@
package org.eclipse.jetty.util.log; package org.eclipse.jetty.util.log;
/** /**
* Slf4jLog Logger * Slf4jLog Logger
*/ */
@ -23,11 +25,31 @@ public class Slf4jLog implements Logger
public Slf4jLog() throws Exception public Slf4jLog() throws Exception
{ {
this("org.eclipse.jetty.util.log"); this("org.eclipse.jetty.util.log");
} }
public Slf4jLog(String name) public Slf4jLog(String name)
{ {
_logger = org.slf4j.LoggerFactory.getLogger( name ); // This checks to make sure that an slf4j implementation is present.
// It is needed because slf4j-api 1.6.x defaults to using NOPLogger.
try
{
Class.forName("org.slf4j.impl.StaticLoggerBinder");
}
catch (ClassNotFoundException ex)
{
throw new NoClassDefFoundError("org.slf4j.impl.StaticLoggerBinder");
}
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger( name );
if (logger instanceof org.slf4j.spi.LocationAwareLogger)
{
_logger = new JettyAwareLogger((org.slf4j.spi.LocationAwareLogger)logger);
}
else
{
_logger = logger;
}
} }
public String getName() public String getName()

View File

@ -19,7 +19,7 @@
<jetty.url>http://www.eclipse.org/jetty</jetty.url> <jetty.url>http://www.eclipse.org/jetty</jetty.url>
<junit-version>4.8.1</junit-version> <junit-version>4.8.1</junit-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j-version>1.5.11</slf4j-version> <slf4j-version>1.6.1</slf4j-version>
<build-support-version>1.0</build-support-version> <build-support-version>1.0</build-support-version>
<jetty.test.helper>1.6</jetty.test.helper> <jetty.test.helper>1.6</jetty.test.helper>
<jetty.test.policy>1.2</jetty.test.policy> <jetty.test.policy>1.2</jetty.test.policy>
@ -352,7 +352,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId> <artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j-version}</version> <version>${slf4j-version}</version>
</dependency> </dependency>
<dependency> <dependency>