From 83f101442cc126dab0ff4bf793f4ed518ff5df19 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 4 Jun 2021 13:17:33 -0500 Subject: [PATCH] Drop jboss-logmanager dependency --- pom.xml | 7 - .../jboss/logging/JBossLogManagerLogger.java | 78 --------- .../logging/JBossLogManagerProvider.java | 150 ------------------ .../org/jboss/logging/LoggerProviders.java | 21 +-- 4 files changed, 1 insertion(+), 255 deletions(-) delete mode 100644 src/main/java/org/jboss/logging/JBossLogManagerLogger.java delete mode 100644 src/main/java/org/jboss/logging/JBossLogManagerProvider.java diff --git a/pom.xml b/pom.xml index 88af23f..03e036c 100644 --- a/pom.xml +++ b/pom.xml @@ -31,17 +31,10 @@ - 2.1.9.Final 1.7.25 - - org.jboss.logmanager - jboss-logmanager - ${version.org.jboss.logmanager} - provided - org.slf4j slf4j-api diff --git a/src/main/java/org/jboss/logging/JBossLogManagerLogger.java b/src/main/java/org/jboss/logging/JBossLogManagerLogger.java deleted file mode 100644 index e4242cf..0000000 --- a/src/main/java/org/jboss/logging/JBossLogManagerLogger.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * - * Copyright 2010 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package org.jboss.logging; - -import org.jboss.logmanager.ExtLogRecord; - -final class JBossLogManagerLogger extends Logger { - - private static final long serialVersionUID = 7429618317727584742L; - - private final org.jboss.logmanager.Logger logger; - - JBossLogManagerLogger(final String name, final org.jboss.logmanager.Logger logger) { - super(name); - this.logger = logger; - } - - public boolean isEnabled(final Level level) { - return logger.isLoggable(translate(level)); - } - - protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) { - java.util.logging.Level translatedLevel = translate(level); - if (logger.isLoggable(translatedLevel)) { - if (parameters == null) { - logger.log(loggerClassName, translatedLevel, String.valueOf(message), thrown); - } else { - logger.log(loggerClassName, translatedLevel, String.valueOf(message), ExtLogRecord.FormatStyle.MESSAGE_FORMAT, parameters, thrown); - } - } - } - - protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) { - if (parameters == null) { - logger.log(loggerClassName, translate(level), format, thrown); - } else { - logger.log(loggerClassName, translate(level), format, ExtLogRecord.FormatStyle.PRINTF, parameters, thrown); - } - } - - private static java.util.logging.Level translate(final Level level) { - if (level == Level.TRACE) { - return org.jboss.logmanager.Level.TRACE; - } else if (level == Level.DEBUG) { - return org.jboss.logmanager.Level.DEBUG; - } - return infoOrHigher(level); - } - - private static java.util.logging.Level infoOrHigher(final Level level) { - if (level == Level.INFO) { - return org.jboss.logmanager.Level.INFO; - } else if (level == Level.WARN) { - return org.jboss.logmanager.Level.WARN; - } else if (level == Level.ERROR) { - return org.jboss.logmanager.Level.ERROR; - } else if (level == Level.FATAL) { - return org.jboss.logmanager.Level.FATAL; - } - return org.jboss.logmanager.Level.ALL; - } -} diff --git a/src/main/java/org/jboss/logging/JBossLogManagerProvider.java b/src/main/java/org/jboss/logging/JBossLogManagerProvider.java deleted file mode 100644 index 6cdbce3..0000000 --- a/src/main/java/org/jboss/logging/JBossLogManagerProvider.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * - * Copyright 2010 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.logging; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.jboss.logmanager.LogContext; -import org.jboss.logmanager.MDC; -import org.jboss.logmanager.NDC; - -import static org.jboss.logmanager.Logger.AttachmentKey; - -final class JBossLogManagerProvider implements LoggerProvider { - - private static final AttachmentKey KEY = new AttachmentKey(); - private static final AttachmentKey> LEGACY_KEY = new AttachmentKey>(); - - public Logger getLogger(final String name) { - final SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - return AccessController.doPrivileged(new PrivilegedAction() { - public Logger run() { - try { - return doGetLogger(name) ; - } catch (NoSuchMethodError ignore) { - } - // fallback - return doLegacyGetLogger(name); - } - }); - } else { - try { - return doGetLogger(name) ; - } catch (NoSuchMethodError ignore) { - } - // fallback - return doLegacyGetLogger(name); - } - } - - private static Logger doLegacyGetLogger(final String name) { - final org.jboss.logmanager.Logger lmLogger = LogContext.getLogContext().getLogger(""); - ConcurrentMap loggers = lmLogger.getAttachment(LEGACY_KEY); - if (loggers == null) { - loggers = new ConcurrentHashMap(); - final ConcurrentMap appearing = lmLogger.attachIfAbsent(LEGACY_KEY, loggers); - if (appearing != null) { - loggers = appearing; - } - } - - Logger l = loggers.get(name); - if (l != null) { - return l; - } - - final org.jboss.logmanager.Logger logger = org.jboss.logmanager.Logger.getLogger(name); - l = new JBossLogManagerLogger(name, logger); - final Logger appearing = loggers.putIfAbsent(name, l); - if (appearing == null) { - return l; - } - return appearing; - } - - private static Logger doGetLogger(final String name) { - Logger l = LogContext.getLogContext().getAttachment(name, KEY); - if (l != null) { - return l; - } - final org.jboss.logmanager.Logger logger = org.jboss.logmanager.Logger.getLogger(name); - l = new JBossLogManagerLogger(name, logger); - Logger a = logger.attachIfAbsent(KEY, l); - if (a == null) { - return l; - } else { - return a; - } - } - - public void clearMdc() { - MDC.clear(); - } - - public Object putMdc(final String key, final Object value) { - return MDC.put(key, String.valueOf(value)); - } - - public Object getMdc(final String key) { - return MDC.get(key); - } - - public void removeMdc(final String key) { - MDC.remove(key); - } - - @SuppressWarnings({ "unchecked" }) - public Map getMdcMap() { - // we can re-define the erasure of this map because MDC does not make further use of the copy - return (Map)MDC.copy(); - } - - public void clearNdc() { - NDC.clear(); - } - - public String getNdc() { - return NDC.get(); - } - - public int getNdcDepth() { - return NDC.getDepth(); - } - - public String popNdc() { - return NDC.pop(); - } - - public String peekNdc() { - return NDC.get(); - } - - public void pushNdc(final String message) { - NDC.push(message); - } - - public void setNdcMaxDepth(final int maxDepth) { - NDC.trimTo(maxDepth); - } -} diff --git a/src/main/java/org/jboss/logging/LoggerProviders.java b/src/main/java/org/jboss/logging/LoggerProviders.java index 8e393d1..2e8c994 100644 --- a/src/main/java/org/jboss/logging/LoggerProviders.java +++ b/src/main/java/org/jboss/logging/LoggerProviders.java @@ -21,7 +21,6 @@ package org.jboss.logging; import java.util.Iterator; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; -import java.util.logging.LogManager; final class LoggerProviders { static final String LOGGING_PROVIDER_KEY = "org.jboss.logging.provider"; @@ -41,9 +40,7 @@ final class LoggerProviders { // Check the system property final String loggerProvider = SecurityActions.getSystemProperty(LOGGING_PROVIDER_KEY); if (loggerProvider != null) { - if ("jboss".equalsIgnoreCase(loggerProvider)) { - return tryJBossLogManager(cl, "system property"); - } else if ("jdk".equalsIgnoreCase(loggerProvider)) { + if ("jdk".equalsIgnoreCase(loggerProvider)) { return tryJDK("system property"); } else if ("slf4j".equalsIgnoreCase(loggerProvider)) { return trySlf4j("system property"); @@ -71,11 +68,6 @@ final class LoggerProviders { } // Finally search the class path - try { - return tryJBossLogManager(cl, null); - } catch (Throwable t) { - // nope... - } try { // only use slf4j if Logback is in use Class.forName("ch.qos.logback.classic.Logger", false, cl); @@ -98,17 +90,6 @@ final class LoggerProviders { return provider; } - private static LoggerProvider tryJBossLogManager(final ClassLoader cl, final String via) throws ClassNotFoundException { - final Class logManagerClass = LogManager.getLogManager().getClass(); - if (logManagerClass == Class.forName("org.jboss.logmanager.LogManager", false, cl) - && Class.forName("org.jboss.logmanager.Logger$AttachmentKey", true, cl).getClassLoader() == logManagerClass.getClassLoader()) { - final LoggerProvider provider = new JBossLogManagerProvider(); - logProvider(provider, via); - return provider; - } - throw new IllegalStateException(); - } - private static void logProvider(final LoggerProvider provider, final String via) { // Log a debug message indicating which logger we are using final Logger logger = provider.getLogger(LoggerProviders.class.getPackage().getName()); -- 2.31.1