Repository: logging-log4j2 Updated Branches: refs/heads/master bfd73824a -> 44943fd5d
Sort members. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3d235a34 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3d235a34 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3d235a34 Branch: refs/heads/master Commit: 3d235a34a33ac42d95186d60a4bbad018a513d45 Parents: 4e1f151 Author: ggregory <[email protected]> Authored: Sat Aug 8 15:55:50 2015 -0700 Committer: ggregory <[email protected]> Committed: Sat Aug 8 15:55:50 2015 -0700 ---------------------------------------------------------------------- .../logging/log4j/core/config/Configurator.java | 108 +++++++++---------- 1 file changed, 54 insertions(+), 54 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3d235a34/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java index 07377aa..7b3aea7 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java @@ -33,11 +33,56 @@ import org.apache.logging.log4j.status.StatusLogger; */ public final class Configurator { + private static final String FQCN = Configurator.class.getName(); + private static final Logger LOGGER = StatusLogger.getLogger(); - private static final String FQCN = Configurator.class.getName(); + private static Log4jContextFactory getFactory() { + final LoggerContextFactory factory = LogManager.getFactory(); + if (factory instanceof Log4jContextFactory) { + return (Log4jContextFactory) factory; + } else if (factory != null) { + LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j.", + factory.getClass().getName(), Log4jContextFactory.class.getName()); + return null; + } else { + LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!"); + return null; + } + } - private Configurator() { + /** + * Initializes the Logging Context. + * @param loader The ClassLoader for the Context (or null). + * @param source The InputSource for the configuration. + * @return The LoggerContext. + */ + public static LoggerContext initialize(final ClassLoader loader, + final ConfigurationSource source) { + return initialize(loader, source, null); + } + + /** + * Initializes the Logging Context. + * @param loader The ClassLoader for the Context (or null). + * @param source The InputSource for the configuration. + * @param externalContext The external context to be attached to the LoggerContext. + * @return The LoggerContext. + */ + + public static LoggerContext initialize(final ClassLoader loader, + final ConfigurationSource source, + final Object externalContext) + { + + try { + final Log4jContextFactory factory = getFactory(); + return factory == null ? null : + factory.getContext(FQCN, loader, externalContext, false, source); + } catch (final Exception ex) { + LOGGER.error("There was a problem obtaining a LoggerContext using the configuration source [{}]", source, ex); + } + return null; } /** @@ -75,16 +120,6 @@ public final class Configurator { /** * Initializes the Logging Context. * @param name The Context name. - * @param configLocation The configuration for the logging context. - * @return The LoggerContext. - */ - public static LoggerContext initialize(final String name, final String configLocation) { - return initialize(name, null, configLocation); - } - - /** - * Initializes the Logging Context. - * @param name The Context name. * @param loader The ClassLoader for the Context (or null). * @param configLocation The configuration for the logging context. * @return The LoggerContext. @@ -117,50 +152,12 @@ public final class Configurator { /** * Initializes the Logging Context. - * @param loader The ClassLoader for the Context (or null). - * @param source The InputSource for the configuration. - * @return The LoggerContext. - */ - public static LoggerContext initialize(final ClassLoader loader, - final ConfigurationSource source) { - return initialize(loader, source, null); - } - - /** - * Initializes the Logging Context. - * @param loader The ClassLoader for the Context (or null). - * @param source The InputSource for the configuration. - * @param externalContext The external context to be attached to the LoggerContext. + * @param name The Context name. + * @param configLocation The configuration for the logging context. * @return The LoggerContext. */ - - public static LoggerContext initialize(final ClassLoader loader, - final ConfigurationSource source, - final Object externalContext) - { - - try { - final Log4jContextFactory factory = getFactory(); - return factory == null ? null : - factory.getContext(FQCN, loader, externalContext, false, source); - } catch (final Exception ex) { - LOGGER.error("There was a problem obtaining a LoggerContext using the configuration source [{}]", source, ex); - } - return null; - } - - private static Log4jContextFactory getFactory() { - final LoggerContextFactory factory = LogManager.getFactory(); - if (factory instanceof Log4jContextFactory) { - return (Log4jContextFactory) factory; - } else if (factory != null) { - LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j.", - factory.getClass().getName(), Log4jContextFactory.class.getName()); - return null; - } else { - LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!"); - return null; - } + public static LoggerContext initialize(final String name, final String configLocation) { + return initialize(name, null, configLocation); } /** @@ -172,4 +169,7 @@ public final class Configurator { ctx.stop(); } } + + private Configurator() { + } }
