Browse Source

KERNEL-9685 refactor: log4j 版本升级

feature/x
Dylan.Liu 3 years ago
parent
commit
6bb8c1d794
  1. 32
      fine-jboss-logging/src/main/java/com/fr/third/org/jboss/logging/Log4j2Logger.java
  2. 2
      fine-jboss-logging/src/main/java/com/fr/third/org/jboss/logging/Log4j2LoggerProvider.java
  3. 8
      fine-jboss-logging/src/main/java/com/fr/third/org/jboss/logging/LoggerProviders.java

32
fine-jboss-logging/src/main/java/com/fr/third/org/jboss/logging/Log4j2Logger.java

@ -18,11 +18,11 @@
package com.fr.third.org.jboss.logging; package com.fr.third.org.jboss.logging;
import org.apache.logging.log4j.LogManager; import com.fr.third.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.LoggingException; import com.fr.third.apache.logging.log4j.LoggingException;
import org.apache.logging.log4j.message.MessageFormatMessageFactory; import com.fr.third.apache.logging.log4j.message.MessageFormatMessageFactory;
import org.apache.logging.log4j.message.StringFormattedMessage; import com.fr.third.apache.logging.log4j.message.StringFormattedMessage;
import org.apache.logging.log4j.spi.AbstractLogger; import com.fr.third.apache.logging.log4j.spi.AbstractLogger;
final class Log4j2Logger extends Logger { final class Log4j2Logger extends Logger {
@ -33,7 +33,7 @@ final class Log4j2Logger extends Logger {
Log4j2Logger(final String name) { Log4j2Logger(final String name) {
super(name); super(name);
org.apache.logging.log4j.Logger logger = LogManager.getLogger(name); com.fr.third.apache.logging.log4j.Logger logger = LogManager.getLogger(name);
if (!(logger instanceof AbstractLogger)) { if (!(logger instanceof AbstractLogger)) {
throw new LoggingException("The logger for [" + name + "] does not extend AbstractLogger. Actual logger: " + logger.getClass().getName()); throw new LoggingException("The logger for [" + name + "] does not extend AbstractLogger. Actual logger: " + logger.getClass().getName());
} }
@ -48,7 +48,7 @@ final class Log4j2Logger extends Logger {
@Override @Override
protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) { protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) {
final org.apache.logging.log4j.Level translatedLevel = Log4j2Logger.translate(level); final com.fr.third.apache.logging.log4j.Level translatedLevel = Log4j2Logger.translate(level);
if (this.logger.isEnabled(translatedLevel)) { if (this.logger.isEnabled(translatedLevel)) {
try { try {
this.logger.logMessage(loggerClassName, translatedLevel, null, this.logger.logMessage(loggerClassName, translatedLevel, null,
@ -60,7 +60,7 @@ final class Log4j2Logger extends Logger {
@Override @Override
protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) { protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) {
final org.apache.logging.log4j.Level translatedLevel = Log4j2Logger.translate(level); final com.fr.third.apache.logging.log4j.Level translatedLevel = Log4j2Logger.translate(level);
if (this.logger.isEnabled(translatedLevel)) { if (this.logger.isEnabled(translatedLevel)) {
try { try {
this.logger.logMessage(loggerClassName, translatedLevel, null, new StringFormattedMessage(format, parameters), thrown); this.logger.logMessage(loggerClassName, translatedLevel, null, new StringFormattedMessage(format, parameters), thrown);
@ -68,17 +68,17 @@ final class Log4j2Logger extends Logger {
} }
} }
private static org.apache.logging.log4j.Level translate(final Level level) { private static com.fr.third.apache.logging.log4j.Level translate(final Level level) {
if (level != null) { if (level != null) {
switch (level) { switch (level) {
case FATAL: return org.apache.logging.log4j.Level.FATAL; case FATAL: return com.fr.third.apache.logging.log4j.Level.FATAL;
case ERROR: return org.apache.logging.log4j.Level.ERROR; case ERROR: return com.fr.third.apache.logging.log4j.Level.ERROR;
case WARN: return org.apache.logging.log4j.Level.WARN; case WARN: return com.fr.third.apache.logging.log4j.Level.WARN;
case INFO: return org.apache.logging.log4j.Level.INFO; case INFO: return com.fr.third.apache.logging.log4j.Level.INFO;
case DEBUG: return org.apache.logging.log4j.Level.DEBUG; case DEBUG: return com.fr.third.apache.logging.log4j.Level.DEBUG;
case TRACE: return org.apache.logging.log4j.Level.TRACE; case TRACE: return com.fr.third.apache.logging.log4j.Level.TRACE;
} }
} }
return org.apache.logging.log4j.Level.ALL; return com.fr.third.apache.logging.log4j.Level.ALL;
} }
} }

2
fine-jboss-logging/src/main/java/com/fr/third/org/jboss/logging/Log4j2LoggerProvider.java

@ -21,7 +21,7 @@ package com.fr.third.org.jboss.logging;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.logging.log4j.ThreadContext; import com.fr.third.apache.logging.log4j.ThreadContext;
final class Log4j2LoggerProvider implements LoggerProvider { final class Log4j2LoggerProvider implements LoggerProvider {

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

@ -121,9 +121,9 @@ final class LoggerProviders {
// JBLOGGING-95 - Add support for Log4j 2.x // JBLOGGING-95 - Add support for Log4j 2.x
private static LoggerProvider tryLog4j2(final ClassLoader cl, final String via) throws ClassNotFoundException { private static LoggerProvider tryLog4j2(final ClassLoader cl, final String via) throws ClassNotFoundException {
Class.forName("org.apache.logging.log4j.Logger", true, cl); Class.forName("com.fr.third.apache.logging.log4j.Logger", true, cl);
Class.forName("org.apache.logging.log4j.LogManager", true, cl); Class.forName("com.fr.third.apache.logging.log4j.LogManager", true, cl);
Class.forName("org.apache.logging.log4j.spi.AbstractLogger", true, cl); Class.forName("com.fr.third.apache.logging.log4j.spi.AbstractLogger", true, cl);
LoggerProvider provider = new Log4j2LoggerProvider(); LoggerProvider provider = new Log4j2LoggerProvider();
// if Log4j 2 has a bad implementation that doesn't extend AbstractLogger, we won't know until getting the first logger throws an exception // if Log4j 2 has a bad implementation that doesn't extend AbstractLogger, we won't know until getting the first logger throws an exception
logProvider(provider, via); logProvider(provider, via);
@ -133,7 +133,7 @@ final class LoggerProviders {
private static LoggerProvider tryLog4j(final ClassLoader cl, final String via) throws ClassNotFoundException { private static LoggerProvider tryLog4j(final ClassLoader cl, final String via) throws ClassNotFoundException {
Class.forName("com.fr.third.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-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 // JBLOGGING-94 - JBoss Logging does not detect com.fr.third.apache.logging.log4j:log4j-1.2-api:2.0
Class.forName("com.fr.third.apache.log4j.config.PropertySetter", true, cl); Class.forName("com.fr.third.apache.log4j.config.PropertySetter", true, cl);
final LoggerProvider provider = new Log4jLoggerProvider(); final LoggerProvider provider = new Log4jLoggerProvider();
logProvider(provider, via); logProvider(provider, via);

Loading…
Cancel
Save