use of org.slf4j.impl.Log4jLoggerAdapter in project alluxio by Alluxio.
the class LogUtils method setLogLevel.
/**
* Gets a logger's level with specify name, if the level argument is not null, it will set to
* specify level first.
* @param logName logger's name
* @param level logger's level
* @return an entity object about the log info
* @throws IOException if an I/O error occurs
*/
public static LogInfo setLogLevel(String logName, String level) throws IOException {
LogInfo result = new LogInfo();
if (StringUtils.isNotBlank(logName)) {
result.setLogName(logName);
Log log = LogFactory.getLog(logName);
Logger logger = LoggerFactory.getLogger(logName);
if (log instanceof Log4JLogger) {
process(((Log4JLogger) log).getLogger(), level, result);
} else if (log instanceof Jdk14Logger) {
process(((Jdk14Logger) log).getLogger(), level, result);
} else if (logger instanceof Log4jLoggerAdapter) {
try {
Field field = Log4jLoggerAdapter.class.getDeclaredField("logger");
field.setAccessible(true);
org.apache.log4j.Logger log4jLogger = (org.apache.log4j.Logger) field.get(logger);
process(log4jLogger, level, result);
} catch (NoSuchFieldException | IllegalAccessException e) {
result.setMessage(e.getMessage());
}
} else {
result.setMessage("Sorry, " + log.getClass() + " not supported.");
}
} else {
result.setMessage("Please specify a correct logName.");
}
return result;
}
Aggregations