357216 - Logging via Log4J does not expand braces in format strings

+ Made JettyAwareLogger more resilient to logger downstream
  implementations by making it perform the slf4j message formatting
  before handing it off to the LocationAwareLogger method(s)
This commit is contained in:
Joakim Erdfelt 2011-09-09 09:51:52 -07:00
parent 03c0192cdb
commit f84c859bbc
3 changed files with 24 additions and 8 deletions

View File

@ -13,9 +13,15 @@
package org.eclipse.jetty.util.log;
import org.slf4j.Marker;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;
/* ------------------------------------------------------------ */
/**
* JettyAwareLogger is used to fix a FQCN bug that arises from how Jetty
* Log uses an indirect slf4j implementation.
*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=276670
*/
class JettyAwareLogger implements org.slf4j.Logger
{
private static final int DEBUG = org.slf4j.spi.LocationAwareLogger.DEBUG_INT;
@ -24,6 +30,7 @@ class JettyAwareLogger implements org.slf4j.Logger
private static final int TRACE = org.slf4j.spi.LocationAwareLogger.TRACE_INT;
private static final int WARN = org.slf4j.spi.LocationAwareLogger.WARN_INT;
private static final String FQCN = Slf4jLog.class.getName();
private final org.slf4j.spi.LocationAwareLogger _logger;
public JettyAwareLogger(org.slf4j.spi.LocationAwareLogger logger)
@ -586,8 +593,19 @@ class JettyAwareLogger implements org.slf4j.Logger
return _logger.toString();
}
private void log(Marker marker, int level, String msg, Object[] objArray, Throwable t)
private void log(Marker marker, int level, String msg, Object[] argArray, Throwable t)
{
_logger.log(marker,"org.eclipse.jetty.util.log.Log",level, msg, objArray,t);
if (argArray == null)
{
// Simple SLF4J Message (no args)
_logger.log(marker,FQCN,level,msg,null,t);
}
else
{
// Don't assume downstream handles argArray properly.
// Do it the SLF4J way here to eliminate that as a bug.
FormattingTuple ft = MessageFormatter.arrayFormat(msg,argArray);
_logger.log(marker,FQCN,level,ft.getMessage(),null,t);
}
}
}

View File

@ -129,10 +129,6 @@ public class Log
return __log;
}
/**
* @deprecated anonymous logging is deprecated, use a named {@link Logger} obtained from {@link #getLogger(String)}
*/
@Deprecated
static boolean isIgnored()
{
return __ignored;

View File

@ -42,6 +42,8 @@ public class Slf4jLog implements Logger
}
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger( name );
// Fix LocationAwareLogger use to indicate FQCN of this class -
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=276670
if (logger instanceof org.slf4j.spi.LocationAwareLogger)
{
_logger = new JettyAwareLogger((org.slf4j.spi.LocationAwareLogger)logger);