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 2015/08/09 02:26:27 UTC

[1/4] logging-log4j2 git commit: Sort members.

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 <gg...@apache.org>
Authored: Sat Aug 8 15:55:50 2015 -0700
Committer: ggregory <gg...@apache.org>
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() {
+    }
 }


[2/4] logging-log4j2 git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Posted by gg...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d0082084
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d0082084
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d0082084

Branch: refs/heads/master
Commit: d0082084ef83f7744326df3f362c5380154b952e
Parents: 3d235a3 c634c5f
Author: ggregory <gg...@apache.org>
Authored: Sat Aug 8 16:04:05 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sat Aug 8 16:04:05 2015 -0700

----------------------------------------------------------------------
 checkstyle.xml | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------



[3/4] logging-log4j2 git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Posted by gg...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/16a83c68
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/16a83c68
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/16a83c68

Branch: refs/heads/master
Commit: 16a83c682faff68417cc075c14420f1166ebbf96
Parents: d008208 bfd7382
Author: ggregory <gg...@apache.org>
Authored: Sat Aug 8 17:18:34 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sat Aug 8 17:18:34 2015 -0700

----------------------------------------------------------------------
 .../log4j/flume/appender/FlumeAvroManager.java  |  9 +++++
 .../log4j/flume/appender/FlumeAppenderTest.java | 42 ++++++++++++++++++--
 src/changes/changes.xml                         |  3 ++
 3 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[4/4] logging-log4j2 git commit: [LOG4J2-1090] Add Core Configurator APIs to change a logger's level.

Posted by gg...@apache.org.
[LOG4J2-1090] Add Core Configurator APIs to change a logger's level.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/44943fd5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/44943fd5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/44943fd5

Branch: refs/heads/master
Commit: 44943fd5de499a932744c869e0f8f9788174acd2
Parents: 16a83c6
Author: ggregory <gg...@apache.org>
Authored: Sat Aug 8 17:26:24 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sat Aug 8 17:26:24 2015 -0700

----------------------------------------------------------------------
 .../log4j/core/config/Configuration.java        |  7 +++++
 .../logging/log4j/core/config/Configurator.java | 29 ++++++++++++++++++++
 .../apache/logging/log4j/core/LoggerTest.java   | 14 ++++++++++
 src/changes/changes.xml                         |  3 ++
 4 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44943fd5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
index c592b05..d8cd780 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
@@ -91,6 +91,12 @@ public interface Configuration extends Filterable {
 
     Map<String, String> getProperties();
 
+    /**
+     * Returns the root Logger.
+     * @return the root Logger.
+     */
+    LoggerConfig getRootLogger();
+
     void addListener(ConfigurationListener listener);
 
     void removeListener(ConfigurationListener listener);
@@ -137,4 +143,5 @@ public interface Configuration extends Filterable {
      * @return the custom levels defined in the current configuration
      */
     List<CustomLevelConfig> getCustomLevels();
+
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44943fd5/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 7b3aea7..33ea726 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
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.config;
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -161,6 +162,34 @@ public final class Configurator {
     }
 
     /**
+     * Sets a logger's level.
+     * @param loggerName the logger name
+     * @param level the new level
+     */
+    public static void setLevel(final String loggerName, final Level level) {
+        final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
+        final LoggerConfig loggerConfig = loggerContext.getConfiguration().getLoggerConfig(loggerName);
+        setLevel(loggerContext, loggerConfig, level);
+    }
+
+    /**
+     * Sets the root logger's level.
+     * @param level the new level
+     */
+    public static void setRootLevel(final Level level) {
+        final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
+        final LoggerConfig loggerConfig = loggerContext.getConfiguration().getRootLogger();
+        setLevel(loggerContext, loggerConfig, level);
+    }
+
+    private static void setLevel(final LoggerContext loggerContext, final LoggerConfig loggerConfig, final Level level) {
+        if (!loggerConfig.getLevel().equals(level)) {
+            loggerConfig.setLevel(level);
+            loggerContext.updateLoggers();
+        }
+    }
+
+    /**
      * Shuts down the given logging context.
      * @param ctx the logging context to shut down, may be null.
      */

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44943fd5/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
index 13f5b7e..73d993d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
@@ -27,6 +27,7 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.junit.InitialLoggerContext;
 import org.apache.logging.log4j.message.MessageFactory;
@@ -104,6 +105,19 @@ public class LoggerTest {
     }
 
     @Test
+    public void debugChangeLevel() {
+        logger.debug("Debug message 1");
+        final List<LogEvent> events = app.getEvents();
+        assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
+        Configurator.setLevel(logger.getName(), Level.OFF);
+        logger.debug("Debug message 2");
+        assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
+        Configurator.setLevel(logger.getName(), Level.DEBUG);
+        logger.debug("Debug message 3");
+        assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 2, events.size());
+    }
+
+    @Test
     public void getLogger_String_MessageFactoryMismatch() {
         final Logger testLogger = testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
                 StringFormatterMessageFactory.INSTANCE, ParameterizedMessageFactory.INSTANCE);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44943fd5/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c381735..f85aa3e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -36,6 +36,9 @@
       <action issue="LOG4J2-1010" dev="rgoers" type="update">
         Pass log event when interpolating logger properties.
       </action>
+      <action issue="LOG4J2-1090" dev="ggregory" type="add">
+        Add Core Configurator APIs to change a logger's level.
+      </action>
       <action issue="LOG4J2-1076" dev="rpopma" type="add">
         Added support for system nanosecond time in pattern layout.
       </action>