Browse Source

DEC-10913 jdk-logger线程blocked,让hibernate日志跟随内置的log4j

research/11.0
Elijah 5 years ago
parent
commit
47f486f9e6
  1. 26
      fine-jboss-logging/src/com/fr/third/org/jboss/logging/Log4jLogger.java
  2. 4
      fine-jboss-logging/src/com/fr/third/org/jboss/logging/Log4jLoggerProvider.java
  3. 4
      fine-jboss-logging/src/com/fr/third/org/jboss/logging/LoggerProviders.java

26
fine-jboss-logging/src/com/fr/third/org/jboss/logging/Log4jLogger.java

@ -24,41 +24,41 @@ final class Log4jLogger extends Logger {
private static final long serialVersionUID = -5446154366955151335L;
private final org.apache.log4j.Logger logger;
private final com.fr.third.apache.log4j.Logger logger;
Log4jLogger(final String name) {
super(name);
logger = org.apache.log4j.Logger.getLogger(name);
logger = com.fr.third.apache.log4j.Logger.getLogger(name);
}
public boolean isEnabled(final Level level) {
final org.apache.log4j.Level l = translate(level);
final com.fr.third.apache.log4j.Level l = translate(level);
return logger.isEnabledFor(l) && l.isGreaterOrEqual(logger.getEffectiveLevel());
}
protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) {
final org.apache.log4j.Level translatedLevel = translate(level);
final com.fr.third.apache.log4j.Level translatedLevel = translate(level);
if (logger.isEnabledFor(translatedLevel)) try {
logger.log(loggerClassName, translatedLevel, parameters == null || parameters.length == 0 ? message : MessageFormat.format(String.valueOf(message), parameters), thrown);
} catch (Throwable ignored) {}
}
protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) {
final org.apache.log4j.Level translatedLevel = translate(level);
final com.fr.third.apache.log4j.Level translatedLevel = translate(level);
if (logger.isEnabledFor(translatedLevel)) try {
logger.log(loggerClassName, translatedLevel, parameters == null ? String.format(format) : String.format(format, parameters), thrown);
} catch (Throwable ignored) {}
}
private static org.apache.log4j.Level translate(final Level level) {
private static com.fr.third.apache.log4j.Level translate(final Level level) {
if (level != null) switch (level) {
case FATAL: return org.apache.log4j.Level.FATAL;
case ERROR: return org.apache.log4j.Level.ERROR;
case WARN: return org.apache.log4j.Level.WARN;
case INFO: return org.apache.log4j.Level.INFO;
case DEBUG: return org.apache.log4j.Level.DEBUG;
case TRACE: return org.apache.log4j.Level.TRACE;
case FATAL: return com.fr.third.apache.log4j.Level.FATAL;
case ERROR: return com.fr.third.apache.log4j.Level.ERROR;
case WARN: return com.fr.third.apache.log4j.Level.WARN;
case INFO: return com.fr.third.apache.log4j.Level.INFO;
case DEBUG: return com.fr.third.apache.log4j.Level.DEBUG;
case TRACE: return com.fr.third.apache.log4j.Level.TRACE;
}
return org.apache.log4j.Level.ALL;
return com.fr.third.apache.log4j.Level.ALL;
}
}

4
fine-jboss-logging/src/com/fr/third/org/jboss/logging/Log4jLoggerProvider.java

@ -21,8 +21,8 @@ package com.fr.third.org.jboss.logging;
import java.util.Collections;
import java.util.Map;
import org.apache.log4j.MDC;
import org.apache.log4j.NDC;
import com.fr.third.apache.log4j.MDC;
import com.fr.third.apache.log4j.NDC;
final class Log4jLoggerProvider implements LoggerProvider {

4
fine-jboss-logging/src/com/fr/third/org/jboss/logging/LoggerProviders.java

@ -131,10 +131,10 @@ final class LoggerProviders {
}
private static LoggerProvider tryLog4j(final ClassLoader cl, final String via) throws ClassNotFoundException {
Class.forName("org.apache.log4j.LogManager", true, cl);
Class.forName("com.fr.third.apache.log4j.LogManager", true, cl);
// JBLOGGING-65 - slf4j can disguise itself as log4j. Test for a class that slf4j doesn't provide.
// JBLOGGING-94 - JBoss Logging does not detect org.apache.logging.log4j:log4j-1.2-api:2.0
Class.forName("org.apache.log4j.config.PropertySetter", true, cl);
Class.forName("com.fr.third.apache.log4j.config.PropertySetter", true, cl);
final LoggerProvider provider = new Log4jLoggerProvider();
logProvider(provider, via);
return provider;

Loading…
Cancel
Save