You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/07 15:50:25 UTC
[logging-log4j2] 01/03: Log4j 1.2 bridge adds org.apache.log4j.spi.NOPLoggerRepository and NOPLogger.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 3d94008bdf8e90ba3eb5438848cab28902ecab43
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jan 7 10:45:29 2022 -0500
Log4j 1.2 bridge adds org.apache.log4j.spi.NOPLoggerRepository and
NOPLogger.
---
.../main/java/org/apache/log4j/spi/NOPLogger.java | 268 +++++++++++++++++++++
.../org/apache/log4j/spi/NOPLoggerRepository.java | 154 ++++++++++++
2 files changed, 422 insertions(+)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/NOPLogger.java b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/NOPLogger.java
new file mode 100644
index 0000000..0c61358
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/NOPLogger.java
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.log4j.spi;
+
+import java.util.Enumeration;
+import java.util.ResourceBundle;
+import java.util.Vector;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+/**
+ * No-operation implementation of Logger used by NOPLoggerRepository.
+ *
+ * @since 1.2.15
+ */
+public final class NOPLogger extends Logger {
+
+ /**
+ * Create instance of Logger.
+ *
+ * @param repo repository, may not be null.
+ * @param name name, may not be null, use "root" for root logger.
+ */
+ public NOPLogger(final NOPLoggerRepository repo, final String name) {
+ super(name);
+ this.repository = repo;
+ this.level = Level.OFF;
+ this.parent = this;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void addAppender(final Appender newAppender) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void assertLog(final boolean assertion, final String msg) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void callAppenders(final LoggingEvent event) {
+ // NOP
+ }
+
+ void closeNestedAppenders() {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void debug(final Object message) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void debug(final Object message, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void error(final Object message) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void error(final Object message, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void fatal(final Object message) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void fatal(final Object message, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Enumeration getAllAppenders() {
+ return new Vector<>().elements();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Appender getAppender(final String name) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Priority getChainedPriority() {
+ return getEffectiveLevel();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Level getEffectiveLevel() {
+ return Level.OFF;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ResourceBundle getResourceBundle() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void info(final Object message) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void info(final Object message, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isAttached(final Appender appender) {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isDebugEnabled() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isEnabledFor(final Priority level) {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isInfoEnabled() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isTraceEnabled() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void l7dlog(final Priority priority, final String key, final Object[] params, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void l7dlog(final Priority priority, final String key, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void log(final Priority priority, final Object message) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void log(final Priority priority, final Object message, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void log(final String callerFQCN, final Priority level, final Object message, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void removeAllAppenders() {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void removeAppender(final Appender appender) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void removeAppender(final String name) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setLevel(final Level level) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setPriority(final Priority priority) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setResourceBundle(final ResourceBundle bundle) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void trace(final Object message) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void trace(final Object message, final Throwable t) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void warn(final Object message) {
+ // NOP
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void warn(final Object message, final Throwable t) {
+ // NOP
+ }
+
+}
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/NOPLoggerRepository.java b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/NOPLoggerRepository.java
new file mode 100644
index 0000000..f64996e
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/NOPLoggerRepository.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.log4j.spi;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.Category;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ * No-operation implementation of LoggerRepository which is used when LogManager.repositorySelector is erroneously
+ * nulled during class reloading.
+ *
+ * @since 1.2.15
+ */
+public final class NOPLoggerRepository implements LoggerRepository {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addHierarchyEventListener(final HierarchyEventListener listener) {
+ // NOP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void emitNoAppenderWarning(final Category cat) {
+ // NOP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Logger exists(final String name) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void fireAddAppenderEvent(final Category logger, final Appender appender) {
+ // NOP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Enumeration getCurrentCategories() {
+ return getCurrentLoggers();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Enumeration getCurrentLoggers() {
+ return new Vector<>().elements();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Logger getLogger(final String name) {
+ return new NOPLogger(this, name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Logger getLogger(final String name, final LoggerFactory factory) {
+ return new NOPLogger(this, name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Logger getRootLogger() {
+ return new NOPLogger(this, "root");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Level getThreshold() {
+ return Level.OFF;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isDisabled(final int level) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void resetConfiguration() {
+ // NOP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setThreshold(final Level level) {
+ // NOP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setThreshold(final String val) {
+ // NOP
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void shutdown() {
+ // NOP
+ }
+}