From bac5439646bcd3e20c30c3614da7d6b5657b73ba Mon Sep 17 00:00:00 2001 From: John Vasileff Date: Sun, 18 Sep 2011 19:44:48 -0400 Subject: [PATCH 3/4] remove dangerous logger factory override Remove LoggerContext support for custom logger factories. All Loggers returned by LoggerContext should be compatibile and of the same type. In the following: Logger getLogger(LoggerFactory factory, String name) the returned Logger was not guaranteed to be created by the provided factory. The value of specifying a custom logger is diminished without this guarantee. Since only one instance of each logger exists, behavior should not be defined by the caller of getLogger() that "wins" the race to be the one to determine the factory used to create the logger. --- .../apache/logging/log4j/spi/LoggerContext.java | 8 ----- .../apache/logging/log4j/spi/LoggerFactory.java | 34 -------------------- .../apache/logging/log4j/SimpleLoggerContext.java | 4 -- .../apache/logging/log4j/core/LoggerContext.java | 17 ++-------- 4 files changed, 3 insertions(+), 60 deletions(-) delete mode 100644 log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerFactory.java diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java b/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java index 300d1d9..e8c39a1 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java @@ -31,14 +31,6 @@ public interface LoggerContext { Logger getLogger(String name); /** - * Return a Logger using the specified factory to create it. - * @param factory The LoggerFactory. - * @param name The name of the Logger. - * @return The Logger with the specified name. - */ - Logger getLogger(LoggerFactory factory, String name); - - /** * Detect if a Logger with the specified name exists. * @param name The Logger name to search for. * @return true if the Logger exists, false otherwise. diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerFactory.java b/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerFactory.java deleted file mode 100644 index ff73ab3..0000000 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.logging.log4j.spi; - -import org.apache.logging.log4j.Logger; - -/** - * Interface implemented by factories that create Logger objects. - * @param The LoogerContext class. - */ -public interface LoggerFactory { - - /** - * Create a new Logger. - * @param ctx The LoggerContext. - * @param name The name of the Logger. - * @return The created Logger. - */ - Logger newInstance(C ctx, String name); -} diff --git a/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java b/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java index 7bf9a40..c7d5e79 100644 --- a/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java +++ b/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java @@ -17,7 +17,6 @@ package org.apache.logging.log4j; import org.apache.logging.log4j.spi.LoggerContext; -import org.apache.logging.log4j.spi.LoggerFactory; /** * @@ -37,7 +36,4 @@ public class SimpleLoggerContext implements LoggerContext { return null; } - public Logger getLogger(LoggerFactory factory, String name) { - return factory.newInstance(this, name); - } } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java index 64d651e..89ee14b 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java @@ -21,7 +21,6 @@ import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationListener; import org.apache.logging.log4j.core.config.NullConfiguration; import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.spi.LoggerFactory; import java.io.File; import java.net.URI; @@ -45,8 +44,6 @@ public class LoggerContext implements org.apache.logging.log4j.spi.LoggerContext private static StatusLogger logger = StatusLogger.getLogger(); - private static final LoggerFactory FACTORY = new Factory(); - private Object externalContext = null; private static final long JVM_START_TIME = System.currentTimeMillis(); @@ -102,17 +99,12 @@ public class LoggerContext implements org.apache.logging.log4j.spi.LoggerContext } public Logger getLogger(String name) { - return getLogger(FACTORY, name); - } - - public Logger getLogger(LoggerFactory factory, String name) { - Logger logger = loggers.get(name); if (logger != null) { return logger; } - logger = (Logger) factory.newInstance(this, name); + logger = newInstance(this, name); Logger prev = loggers.putIfAbsent(name, logger); return prev == null ? logger : prev; } @@ -188,10 +180,7 @@ public class LoggerContext implements org.apache.logging.log4j.spi.LoggerContext reconfigure(); } - private static class Factory implements LoggerFactory { - - public Logger newInstance(LoggerContext ctx, String name) { - return new Logger(ctx, name); - } + private Logger newInstance(LoggerContext ctx, String name) { + return new Logger(ctx, name); } } -- 1.7.6