Skip to content

Commit

Permalink
Merge pull request #4570 from eclipse/jetty-10.0.x-4567-StdErrLog-thr…
Browse files Browse the repository at this point in the history
…owable

Issue #4567 - StdErrLog cleanup and final Arg Throwable support
  • Loading branch information
joakime authored Feb 20, 2020
2 parents 9683142 + 4ec8826 commit e8d0be4
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@
*/
public class JavaUtilLog extends AbstractLogger
{
private static final String THIS_CLASS = JavaUtilLog.class.getName();
private static final boolean __source =
Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.SOURCE",
Log.__props.getProperty("org.eclipse.jetty.util.log.javautil.SOURCE", "true")));
private static final boolean SOURCE =
Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.SOURCE",
Log.getProperty("org.eclipse.jetty.util.log.javautil.SOURCE", "true")));

private static boolean _initialized = false;
private static boolean __initialized = false;

private Level configuredLevel;
private Level _configuredLevel;
private java.util.logging.Logger _logger;

public JavaUtilLog()
Expand All @@ -82,11 +81,11 @@ public JavaUtilLog(String name)
{
synchronized (JavaUtilLog.class)
{
if (!_initialized)
if (!__initialized)
{
_initialized = true;
__initialized = true;

final String properties = Log.__props.getProperty("org.eclipse.jetty.util.log.javautil.PROPERTIES", null);
final String properties = Log.getProperty("org.eclipse.jetty.util.log.javautil.PROPERTIES", null);
if (properties != null)
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
Expand Down Expand Up @@ -115,7 +114,7 @@ public Object run()

_logger = java.util.logging.Logger.getLogger(name);

switch (lookupLoggingLevel(Log.__props, name))
switch (lookupLoggingLevel(Log.getProperties(), name))
{
case LEVEL_ALL:
_logger.setLevel(Level.ALL);
Expand All @@ -137,7 +136,7 @@ public Object run()
break;
}

configuredLevel = _logger.getLevel();
_configuredLevel = _logger.getLevel();
}

@Override
Expand All @@ -152,13 +151,13 @@ protected void log(Level level, String msg, Throwable thrown)
if (thrown != null)
record.setThrown(thrown);
record.setLoggerName(_logger.getName());
if (__source)
if (SOURCE)
{
StackTraceElement[] stack = new Throwable().getStackTrace();
for (int i = 0; i < stack.length; i++)
{
StackTraceElement e = stack[i];
if (!e.getClassName().equals(THIS_CLASS))
if (!e.getClassName().equals(JavaUtilLog.class.getName()))
{
record.setSourceClassName(e.getClassName());
record.setSourceMethodName(e.getMethodName());
Expand Down Expand Up @@ -222,12 +221,12 @@ public void setDebugEnabled(boolean enabled)
{
if (enabled)
{
configuredLevel = _logger.getLevel();
_configuredLevel = _logger.getLevel();
_logger.setLevel(Level.FINE);
}
else
{
_logger.setLevel(configuredLevel);
_logger.setLevel(_configuredLevel);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public static void config()

public JettyLogHandler()
{
if (Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.DEBUG", "false")))
if (Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.DEBUG", "false")))
{
setLevel(Level.FINEST);
}

if (Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.IGNORED", "false")))
if (Boolean.parseBoolean(Log.getProperty("org.eclipse.jetty.util.log.IGNORED", "false")))
{
setLevel(Level.ALL);
}
Expand Down
29 changes: 17 additions & 12 deletions jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public class Log
/**
* Logging Configuration Properties
*/
protected static final Properties __props = new Properties();
private static final ConcurrentMap<String, Logger> __loggers = new ConcurrentHashMap<>();
protected static final Properties PROPS = new Properties();
private static final ConcurrentMap<String, Logger> LOGGERS = new ConcurrentHashMap<>();
private static boolean __initialized;
private static Logger LOG;

Expand All @@ -83,7 +83,7 @@ public Object run()
// * This is an optional feature used by embedded mode use, and test cases to allow for early
// * configuration of the Log class in situations where access to the System.properties are
// * either too late or just impossible.
loadProperties("jetty-logging.properties", __props);
loadProperties("jetty-logging.properties", PROPS);

// Next see if an OS specific jetty-logging.properties object exists in the classpath.
// This really for setting up test specific logging behavior based on OS.
Expand All @@ -92,7 +92,7 @@ public Object run()
{
// NOTE: cannot use jetty-util's StringUtil.replace() as it may initialize logging itself.
osName = osName.toLowerCase(Locale.ENGLISH).replace(' ', '-');
loadProperties("jetty-logging-" + osName + ".properties", __props);
loadProperties("jetty-logging-" + osName + ".properties", PROPS);
}

// Now load the System.properties as-is into the __props,
Expand All @@ -105,12 +105,12 @@ public Object run()
String val = System.getProperty(key);
// Protect against application code insertion of non-String values (returned as null).
if (val != null)
__props.setProperty(key, val);
PROPS.setProperty(key, val);
}

// Now use the configuration properties to configure the Log statics.
__logClass = __props.getProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.Slf4jLog");
__ignored = Boolean.parseBoolean(__props.getProperty("org.eclipse.jetty.util.log.IGNORED", "false"));
__logClass = PROPS.getProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.Slf4jLog");
__ignored = Boolean.parseBoolean(PROPS.getProperty("org.eclipse.jetty.util.log.IGNORED", "false"));
return null;
}
});
Expand Down Expand Up @@ -148,7 +148,7 @@ public static void initialized()
return;
__initialized = true;

boolean announce = Boolean.parseBoolean(__props.getProperty("org.eclipse.jetty.util.log.announce", "true"));
boolean announce = Boolean.parseBoolean(PROPS.getProperty("org.eclipse.jetty.util.log.announce", "true"));
try
{
Class<?> logClass = Loader.loadClass(Log.class, __logClass);
Expand Down Expand Up @@ -278,7 +278,7 @@ public static Logger getLogger(String name)
if (name == null)
return LOG;

Logger logger = __loggers.get(name);
Logger logger = LOGGERS.get(name);
if (logger == null)
logger = LOG.getLogger(name);

Expand All @@ -287,7 +287,7 @@ public static Logger getLogger(String name)

static ConcurrentMap<String, Logger> getMutableLoggers()
{
return __loggers;
return LOGGERS;
}

/**
Expand All @@ -298,11 +298,16 @@ static ConcurrentMap<String, Logger> getMutableLoggers()
@ManagedAttribute("list of all instantiated loggers")
public static Map<String, Logger> getLoggers()
{
return Collections.unmodifiableMap(__loggers);
return Collections.unmodifiableMap(LOGGERS);
}

public static Properties getProperties()
{
return __props;
return PROPS;
}

public static String getProperty(String key, String defaultValue)
{
return PROPS.getProperty(key, defaultValue);
}
}
30 changes: 15 additions & 15 deletions jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,73 +26,73 @@ public interface Logger
/**
* @return the name of this logger
*/
public String getName();
String getName();

/**
* Formats and logs at warn level.
*
* @param msg the formatting string
* @param args the optional arguments
*/
public void warn(String msg, Object... args);
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);
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);
void warn(String msg, Throwable thrown);

/**
* Formats and logs at info level.
*
* @param msg the formatting string
* @param args the optional arguments
*/
public void info(String msg, Object... args);
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);
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);
void info(String msg, Throwable thrown);

/**
* @return whether the debug level is enabled
*/
public boolean isDebugEnabled();
boolean isDebugEnabled();

/**
* Mutator used to turn debug on programmatically.
*
* @param enabled whether to enable the debug level
*/
public void setDebugEnabled(boolean enabled);
void setDebugEnabled(boolean enabled);

/**
* Formats and logs at debug level.
*
* @param msg the formatting string
* @param args the optional arguments
*/
public void debug(String msg, Object... args);
void debug(String msg, Object... args);

/**
* Formats and logs at debug level.
Expand All @@ -101,34 +101,34 @@ public interface Logger
* @param msg the formatting string
* @param value long value
*/
public void debug(String msg, long value);
void debug(String msg, long value);

/**
* Logs the given Throwable information at debug level
*
* @param thrown the Throwable to log
*/
public void debug(Throwable thrown);
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);
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);
Logger getLogger(String name);

/**
* Ignore an exception.
* <p>This should be used rather than an empty catch block.
*
* @param ignored the throwable to log as ignored
*/
public void ignore(Throwable ignored);
void ignore(Throwable ignored);
}
Loading

0 comments on commit e8d0be4

Please sign in to comment.