-
Notifications
You must be signed in to change notification settings - Fork 9k
HADOOP-18653. LogLevel servlet to determine log impl before using setLevel #5456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@steveloughran This PR is a follow-up task from #5315 (comment here) Could you please review this PR? For the error case, it's difficult to write any UT as we can't remove slf4j-log4j jar from classpath for a given test. |
@Apache9 @jojochuang could you please also take a look? |
🎊 +1 overall
This message was automatically generated. |
if (GenericsUtil.isLog4jLogger(logName)) { | ||
process(Logger.getLogger(logName), level, out); | ||
} else { | ||
out.println("Sorry, " + log.getClass() + " not supported.<br />"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text to explain "log4j loggers only"
@@ -89,10 +89,30 @@ public static boolean isLog4jLogger(Class<?> clazz) { | |||
} | |||
Logger log = LoggerFactory.getLogger(clazz); | |||
try { | |||
Class log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter"); | |||
Class<?> log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this a constant string and use everyw 8000 here it is needed
} | ||
Logger log = LoggerFactory.getLogger(logger); | ||
try { | ||
Class<?> log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the class isn't found, then that fact can be remembered in an atomic boolean so future loads/checks skipped.
🎊 +1 overall
This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like the changes; final bit of tuning needed
@@ -103,14 +113,15 @@ public static boolean isLog4jLogger(Class<?> clazz) { | |||
* @return true if the logger uses Log4J implementation. | |||
*/ | |||
public static boolean isLog4jLogger(String logger) { | |||
if (logger == null) { | |||
if (logger == null || !IS_LOG4J_LOGGER.get()) { | |||
return false; | |||
} | |||
Logger log = LoggerFactory.getLogger(logger); | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this try/catch is a duplicate of isLog4jLogger(class).
why not do isLog4jLogger(LoggerFactory.getLogger(logger))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the other way around would be more appropriate?
For instance, in slf4j implementation, they have:
public static Logger getLogger(Class<?> clazz) {
Logger logger = getLogger(clazz.getName());
...
...
Hence, we can also call clazz.getName() here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to keep the logic in only one utility method. The other method will just call this one. Simplified (exactly as slf4j library methods).
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
+1
…Level (apache#5456) The log level can only be set on Log4J log implementations; probes are used to downgrade to a warning when other logging back ends are used Contributed by Viraj Jasani
LogLevel GET API is used to set log level for a given class name dynamically. While we have cleaned up the commons-logging references, it would be great to determine whether slf4j log4j adapter is in the classpath before allowing client to set the log level.
Proposed changes: