You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2014/09/25 19:24:13 UTC

[1/6] git commit: LOG4J2-589 CustomLevelPlugin initial version.

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-589 [created] bfbcc93b0


LOG4J2-589 CustomLevelPlugin initial version.

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

Branch: refs/heads/LOG4J2-589
Commit: 5427dea87da1ce36f1a740beea0e6470e1c856bf
Parents: e4a9d7f
Author: rpopma <rp...@apache.org>
Authored: Thu Sep 25 00:49:46 2014 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Sep 25 20:51:32 2014 +0900

----------------------------------------------------------------------
 .../core/config/AbstractConfiguration.java      |  2 +
 .../log4j/core/config/CustomLevelPlugin.java    | 49 ++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5427dea8/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index c7699c9..28a22cb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -371,6 +371,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
                     root = l.getRoot();
                     setRoot = true;
                 }
+            } else if (child.getObject() instanceof Level) {
+                // nothing to do: plugin already created custom level
             } else {
                 LOGGER.error("Unknown object \"{}\" of type {} is ignored.", child.getName(),
                         child.getObject().getClass().getName());

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5427dea8/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
new file mode 100644
index 0000000..ba0a260
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
@@ -0,0 +1,49 @@
+/*
+ * 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.core.config;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+
+/**
+ * Custom Level object that is created via configuration.
+ */
+@Plugin(name = "CustomLevel", category = "Core") // TBD: category="Level" does not work... Why?
+public final class CustomLevelPlugin {
+
+    private CustomLevelPlugin() {
+    }
+
+    /**
+     * Creates a custom Level object.
+     * 
+     * @param levelName name of the custom level.
+     * @param intLevel the intLevel that determines where this level resides relative to the built-in levels
+     * @return A Level object.
+     */
+    @PluginFactory
+    public static Level createLevel(
+// @formatter:off
+            @PluginAttribute("name") final String levelName,
+            @PluginAttribute("intLevel") final int intLevel) {
+        // @formatter:on
+        Level result = Level.forName(levelName, intLevel);
+        return result;
+    }
+}


[5/6] git commit: LOG4J2-589 updated schema without outer CustomLevels container element

Posted by rp...@apache.org.
LOG4J2-589 updated schema without outer CustomLevels container element

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

Branch: refs/heads/LOG4J2-589
Commit: 9ea5090065bdeceedfd4ca76271b7761ce0640bd
Parents: d30ea90
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 26 02:21:11 2014 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 26 02:21:11 2014 +0900

----------------------------------------------------------------------
 log4j-core/src/main/resources/Log4j-config.xsd | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9ea50900/log4j-core/src/main/resources/Log4j-config.xsd
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/resources/Log4j-config.xsd b/log4j-core/src/main/resources/Log4j-config.xsd
index 8f492d1..20c1500 100644
--- a/log4j-core/src/main/resources/Log4j-config.xsd
+++ b/log4j-core/src/main/resources/Log4j-config.xsd
@@ -20,10 +20,7 @@
     <xs:element name="Configuration" type="ConfigurationType"/>
     <xs:complexType name="ConfigurationType">
         <xs:sequence>
-            <xs:choice minOccurs="0" maxOccurs="1">
-                <xs:element name="CustomLevels" type="CustomLevelsType"/>
-                <xs:element name="CustomLevel" type="CustomLevelType"/>
-            </xs:choice>
+            <xs:element name="CustomLevel" type="CustomLevelType"/>
             <xs:element name="Properties" type="PropertiesType"/>
             <xs:choice minOccurs="0" maxOccurs="1">
                 <xs:element name="Filters" type="FiltersType"/>


[3/6] git commit: LOG4J2-589 improved comments

Posted by rp...@apache.org.
LOG4J2-589 improved comments

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

Branch: refs/heads/LOG4J2-589
Commit: b534ca2ffef68dfb241602079b2d851a87eb6691
Parents: 9f76d5e
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 26 02:18:33 2014 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 26 02:18:33 2014 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/config/AbstractConfiguration.java   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b534ca2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index 28a22cb..325545b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -372,7 +372,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
                     setRoot = true;
                 }
             } else if (child.getObject() instanceof Level) {
-                // nothing to do: plugin already created custom level
+                // This else clause prevents the warning message below from being logged.
+                // Nothing to do: plugin already created the custom Level instance.
             } else {
                 LOGGER.error("Unknown object \"{}\" of type {} is ignored.", child.getName(),
                         child.getObject().getClass().getName());


Re: [2/6] git commit: LOG4J2-589 Added logging, minor improvements.

Posted by Remko Popma <re...@gmail.com>.
To be honest I'm still not really clear on that bit. I found some code that handles plug-ins of category "level" but that code works differently than I expect...

I will add some new questions in the Jira comments soon. 

Sent from my iPhone

> On 2014/09/26, at 2:57, Matt Sicker <bo...@gmail.com> wrote:
> 
> You figured out the category thing, right? It's because anything that's an XML element has to be in the Core category (which is what the Core category seems to be for).
> 
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> Date: 25 September 2014 12:24
> Subject: [2/6] git commit: LOG4J2-589 Added logging, minor improvements.
> To: commits@logging.apache.org
> 
> 
> LOG4J2-589 Added logging, minor improvements.
> 
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9f76d5eb
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9f76d5eb
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9f76d5eb
> 
> Branch: refs/heads/LOG4J2-589
> Commit: 9f76d5eba818269aa5474207519b9b4d9e2e6448
> Parents: 5427dea
> Author: rpopma <rp...@apache.org>
> Authored: Fri Sep 26 02:15:21 2014 +0900
> Committer: rpopma <rp...@apache.org>
> Committed: Fri Sep 26 02:17:58 2014 +0900
> 
> ----------------------------------------------------------------------
>  .../apache/logging/log4j/core/config/CustomLevelPlugin.java  | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9f76d5eb/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> index ba0a260..532e811 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> @@ -20,11 +20,12 @@ import org.apache.logging.log4j.Level;
>  import org.apache.logging.log4j.core.config.plugins.Plugin;
>  import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> +import org.apache.logging.log4j.status.StatusLogger;
> 
>  /**
>   * Custom Level object that is created via configuration.
>   */
> -@Plugin(name = "CustomLevel", category = "Core") // TBD: category="Level" does not work... Why?
> +@Plugin(name = "CustomLevel", category = "Core", printObject = true)
>  public final class CustomLevelPlugin {
> 
>      private CustomLevelPlugin() {
> @@ -38,11 +39,12 @@ public final class CustomLevelPlugin {
>       * @return A Level object.
>       */
>      @PluginFactory
> -    public static Level createLevel(
> -// @formatter:off
> +    public static Level createLevel(// @formatter:off
>              @PluginAttribute("name") final String levelName,
>              @PluginAttribute("intLevel") final int intLevel) {
>          // @formatter:on
> +
> +        StatusLogger.getLogger().debug("Creating CustomLevel(name='{}', intValue={})", levelName, intLevel);
>          Level result = Level.forName(levelName, intLevel);
>          return result;
>      }
> 
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>

Re: [2/6] git commit: LOG4J2-589 Added logging, minor improvements.

Posted by Ralph Goers <ra...@dslextreme.com>.
That isn’t quite accurate.

The category really identifies the set of Plugins that a specific caller of PluginManager wants.  For example, PattermLayout only wants PatternConverters, not Appenders, etc., the Interpolator only wants Lookups, Flume wants a SecretKey provider and the Configuration picks up most everything else (“Core”).

Ralph



On Sep 25, 2014, at 10:57 AM, Matt Sicker <bo...@gmail.com> wrote:

> You figured out the category thing, right? It's because anything that's an XML element has to be in the Core category (which is what the Core category seems to be for).
> 
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> Date: 25 September 2014 12:24
> Subject: [2/6] git commit: LOG4J2-589 Added logging, minor improvements.
> To: commits@logging.apache.org
> 
> 
> LOG4J2-589 Added logging, minor improvements.
> 
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/9f76d5eb
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9f76d5eb
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9f76d5eb
> 
> Branch: refs/heads/LOG4J2-589
> Commit: 9f76d5eba818269aa5474207519b9b4d9e2e6448
> Parents: 5427dea
> Author: rpopma <rp...@apache.org>
> Authored: Fri Sep 26 02:15:21 2014 +0900
> Committer: rpopma <rp...@apache.org>
> Committed: Fri Sep 26 02:17:58 2014 +0900
> 
> ----------------------------------------------------------------------
>  .../apache/logging/log4j/core/config/CustomLevelPlugin.java  | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9f76d5eb/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> index ba0a260..532e811 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
> @@ -20,11 +20,12 @@ import org.apache.logging.log4j.Level;
>  import org.apache.logging.log4j.core.config.plugins.Plugin;
>  import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> +import org.apache.logging.log4j.status.StatusLogger;
> 
>  /**
>   * Custom Level object that is created via configuration.
>   */
> -@Plugin(name = "CustomLevel", category = "Core") // TBD: category="Level" does not work... Why?
> +@Plugin(name = "CustomLevel", category = "Core", printObject = true)
>  public final class CustomLevelPlugin {
> 
>      private CustomLevelPlugin() {
> @@ -38,11 +39,12 @@ public final class CustomLevelPlugin {
>       * @return A Level object.
>       */
>      @PluginFactory
> -    public static Level createLevel(
> -// @formatter:off
> +    public static Level createLevel(// @formatter:off
>              @PluginAttribute("name") final String levelName,
>              @PluginAttribute("intLevel") final int intLevel) {
>          // @formatter:on
> +
> +        StatusLogger.getLogger().debug("Creating CustomLevel(name='{}', intValue={})", levelName, intLevel);
>          Level result = Level.forName(levelName, intLevel);
>          return result;
>      }
> 
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>


Fwd: [2/6] git commit: LOG4J2-589 Added logging, minor improvements.

Posted by Matt Sicker <bo...@gmail.com>.
You figured out the category thing, right? It's because anything that's an
XML element has to be in the Core category (which is what the Core category
seems to be for).

---------- Forwarded message ----------
From: <rp...@apache.org>
Date: 25 September 2014 12:24
Subject: [2/6] git commit: LOG4J2-589 Added logging, minor improvements.
To: commits@logging.apache.org


LOG4J2-589 Added logging, minor improvements.

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

Branch: refs/heads/LOG4J2-589
Commit: 9f76d5eba818269aa5474207519b9b4d9e2e6448
Parents: 5427dea
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 26 02:15:21 2014 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 26 02:17:58 2014 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/config/CustomLevelPlugin.java  | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9f76d5eb/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
index ba0a260..532e811 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
@@ -20,11 +20,12 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.status.StatusLogger;

 /**
  * Custom Level object that is created via configuration.
  */
-@Plugin(name = "CustomLevel", category = "Core") // TBD: category="Level"
does not work... Why?
+@Plugin(name = "CustomLevel", category = "Core", printObject = true)
 public final class CustomLevelPlugin {

     private CustomLevelPlugin() {
@@ -38,11 +39,12 @@ public final class CustomLevelPlugin {
      * @return A Level object.
      */
     @PluginFactory
-    public static Level createLevel(
-// @formatter:off
+    public static Level createLevel(// @formatter:off
             @PluginAttribute("name") final String levelName,
             @PluginAttribute("intLevel") final int intLevel) {
         // @formatter:on
+
+        StatusLogger.getLogger().debug("Creating CustomLevel(name='{}',
intValue={})", levelName, intLevel);
         Level result = Level.forName(levelName, intLevel);
         return result;
     }




-- 
Matt Sicker <bo...@gmail.com>

[2/6] git commit: LOG4J2-589 Added logging, minor improvements.

Posted by rp...@apache.org.
LOG4J2-589 Added logging, minor improvements.

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

Branch: refs/heads/LOG4J2-589
Commit: 9f76d5eba818269aa5474207519b9b4d9e2e6448
Parents: 5427dea
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 26 02:15:21 2014 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 26 02:17:58 2014 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/config/CustomLevelPlugin.java  | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9f76d5eb/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
index ba0a260..532e811 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelPlugin.java
@@ -20,11 +20,12 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.status.StatusLogger;
 
 /**
  * Custom Level object that is created via configuration.
  */
-@Plugin(name = "CustomLevel", category = "Core") // TBD: category="Level" does not work... Why?
+@Plugin(name = "CustomLevel", category = "Core", printObject = true)
 public final class CustomLevelPlugin {
 
     private CustomLevelPlugin() {
@@ -38,11 +39,12 @@ public final class CustomLevelPlugin {
      * @return A Level object.
      */
     @PluginFactory
-    public static Level createLevel(
-// @formatter:off
+    public static Level createLevel(// @formatter:off
             @PluginAttribute("name") final String levelName,
             @PluginAttribute("intLevel") final int intLevel) {
         // @formatter:on
+
+        StatusLogger.getLogger().debug("Creating CustomLevel(name='{}', intValue={})", levelName, intLevel);
         Level result = Level.forName(levelName, intLevel);
         return result;
     }


[4/6] git commit: LOG4J2-589 initial schema with outer CustomLevels container element

Posted by rp...@apache.org.
LOG4J2-589 initial schema with outer CustomLevels container element

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

Branch: refs/heads/LOG4J2-589
Commit: d30ea90faacf35fe743bdc729ec399e60f3520ae
Parents: b534ca2
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 26 02:20:17 2014 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 26 02:20:17 2014 +0900

----------------------------------------------------------------------
 log4j-core/src/main/resources/Log4j-config.xsd | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d30ea90f/log4j-core/src/main/resources/Log4j-config.xsd
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/resources/Log4j-config.xsd b/log4j-core/src/main/resources/Log4j-config.xsd
index a19e125..8f492d1 100644
--- a/log4j-core/src/main/resources/Log4j-config.xsd
+++ b/log4j-core/src/main/resources/Log4j-config.xsd
@@ -20,6 +20,10 @@
     <xs:element name="Configuration" type="ConfigurationType"/>
     <xs:complexType name="ConfigurationType">
         <xs:sequence>
+            <xs:choice minOccurs="0" maxOccurs="1">
+                <xs:element name="CustomLevels" type="CustomLevelsType"/>
+                <xs:element name="CustomLevel" type="CustomLevelType"/>
+            </xs:choice>
             <xs:element name="Properties" type="PropertiesType"/>
             <xs:choice minOccurs="0" maxOccurs="1">
                 <xs:element name="Filters" type="FiltersType"/>
@@ -112,6 +116,15 @@
             <xs:element name="Filter" type="FilterType" minOccurs="0" maxOccurs="unbounded"/>
         </xs:sequence>
     </xs:complexType>
+    <xs:complexType name="CustomLevelType">
+        <xs:attribute name="name" type="xs:string" use="required"/>
+        <xs:attribute name="intLevel" type="xs:string" use="required"/>
+    </xs:complexType>
+    <xs:complexType name="CustomLevelsType">
+        <xs:sequence>
+            <xs:element name="CustomLevel" type="CustomLevelType" minOccurs="0" maxOccurs="unbounded"/>
+        </xs:sequence>
+    </xs:complexType>
     <xs:complexType name="LoggersType" mixed="true">
         <xs:sequence>
             <xs:element name="Logger" type="LoggerType" minOccurs="0" maxOccurs="unbounded"/>


[6/6] git commit: LOG4J2-589 docs: user manual updates

Posted by rp...@apache.org.
LOG4J2-589 docs: user manual updates

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

Branch: refs/heads/LOG4J2-589
Commit: bfbcc93b0bb53e33e4100c8bb329093adb54de15
Parents: 9ea5090
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 26 02:22:07 2014 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 26 02:22:07 2014 +0900

----------------------------------------------------------------------
 src/site/site.xml                           |   2 +
 src/site/xdoc/manual/customloglevels.xml.vm | 116 ++++++++++++++++++++---
 2 files changed, 105 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bfbcc93b/src/site/site.xml
----------------------------------------------------------------------
diff --git a/src/site/site.xml b/src/site/site.xml
index 8b62c1d..7f538b8 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -181,6 +181,8 @@
       </item>
 
       <item name="Custom Log Levels" href="/manual/customloglevels.html" collapse="true">
+        <item name="In Code" href="/manual/customloglevels.html#DefiningLevelsInCode"/>
+        <item name="In Configuration" href="/manual/customloglevels.html#DefiningLevelsInConfiguration"/>
         <item name="Adding or Replacing Levels" href="/manual/customloglevels.html#AddingOrReplacingLevels"/>
         <item name="Custom Loggers" href="/manual/customloglevels.html#CustomLoggers"/>
         <item name="Custom Logger Example" href="/manual/customloglevels.html#ExampleUsage"/>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bfbcc93b/src/site/xdoc/manual/customloglevels.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/customloglevels.xml.vm b/src/site/xdoc/manual/customloglevels.xml.vm
index 0cd6149..cdb0108 100644
--- a/src/site/xdoc/manual/customloglevels.xml.vm
+++ b/src/site/xdoc/manual/customloglevels.xml.vm
@@ -27,18 +27,34 @@
     <body>
       <a name="top" />
       <section name="Custom Log Levels">
+        <a name="DefiningLevelsInCode" />
+        <subsection name="Defining Custom Log Levels in Code">
         <p>
-          Log4J 2 supports custom log levels. The <tt>Level.forName()</tt> method creates a new
-          level for the specified name. By calling the Logger.log() method and passing this
-          custom log level you can log messages at this level:
+          Log4J 2 supports custom log levels. Custom log levels can be defined in code
+          or in configuration. To define a custom log level in code, use the
+          <tt>Level.forName()</tt> method. This method creates a new
+          level for the specified name. After a log level is defined you can log
+          messages at this level by calling the Logger.log() method and passing
+          the custom log level:
         </p>
             <pre class="prettyprint">
-final Logger logger = LogManager.getLogger();
+// This creates the "VERBOSE" level if it does not exist yet.
 final Level VERBOSE = Level.forName("VERBOSE", 550);
 
-logger.log(VERBOSE, "a verbose message");
-logger.log(VERBOSE, "another message");</pre>
-        <p>When defining a custom log level, the <tt>intLevel</tt> parameter (550 in the example above) determines
+final Logger logger = LogManager.getLogger();
+logger.log(VERBOSE, "a verbose message"); // use the custom VERBOSE level
+
+// Create and use a new custom level "DIAG".
+logger.log(Level.forName("DIAG", 350), "a diagnostic message");
+
+// Use (don't create) the "DIAG" custom level.
+// Only do this *after* the custom level is created!
+logger.log(Level.getLevel("DIAG"), "another diagnostic message");
+
+// Using an undefined level results in an error: Level.getLevel() returns null,
+// and logger.log(null, "message") throws an exception.
+logger.log(Level.getLevel("FORGOT_TO_DEFINE"), "some message"); // throws exception!</pre>
+        <p>When defining a custom log level, the <tt>intLevel</tt> parameter (550 and 350 in the example above) determines
            where the custom level exists in relation to the standard levels built-in to Log4J 2.
            For reference, the table below shows the <tt>intLevel</tt> of the built-in log levels.
          </p>
@@ -80,8 +96,71 @@ logger.log(VERBOSE, "another message");</pre>
             <td>ALL</td>
             <td align="right"><tt>Integer.MAX_VALUE</tt></td>
           </tr>
-        </table>          
-         
+        </table>
+        </subsection>
+        <a name="DefiningLevelsInConfiguration" />
+        <subsection name="Defining Custom Log Levels in Configuration">
+          <p>
+          Custom log levels can also be defined in configuration.
+          This is convenient for using a custom level in a logger filter
+          or an appender filter. Similar to defining log levels in code,
+          a custom level must be defined first, before it can be used.
+          If a logger or appender is configured with an undefined level,
+          that logger or appender will be invalid and will not process any log events.
+          </p>
+          <p>
+            The <b>CustomLevel</b> configuration element creates a custom level.
+            Internally it calls the same <tt>Level.forName()</tt> method discussed above.
+          </p>
+          <table>
+            <caption align="top">CustomLevel Parameters</caption>
+            <tr>
+              <th>Parameter Name</th>
+              <th>Type</th>
+              <th>Description</th>
+            </tr>
+            <tr>
+              <td>name</td>
+              <td>String</td>
+              <td>The name of the custom level. Note that level names are case sensitive.
+                The convention is to use all upper-case names.</td>
+            </tr>
+            <tr>
+              <td>intLevel</td>
+              <td>integer</td>
+              <td>Determines where the custom level exists in relation to the
+                standard levels built-in to Log4J 2 (see the table above).</td>
+            </tr>
+          </table>
+          <p>
+          The following example shows a configuration that defines some custom
+          log levels and uses a custom log level to filter log events sent to the console.
+          </p>
+          <pre class="prettyprint linenums"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+  <!-- Define custom levels before using them for filtering below. -->
+  <CustomLevel name="DIAG" intLevel="350" />
+  <CustomLevel name="NOTICE" intLevel="450" />
+  <CustomLevel name="VERBOSE" intLevel="550" />
+  
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d %-7level %logger{36} - %msg%n"/>
+    </Console>
+    <File name="MyFile" fileName="logs/app.log">
+      <PatternLayout pattern="%d %-7level %logger{36} - %msg%n"/>
+    </File>
+  </Appenders>
+  <Loggers>
+    <Root level="trace">
+      <!-- Only events at DIAG level or more specific are sent to the console. -->
+      <AppenderRef ref="Console" level="diag" />
+      <AppenderRef ref="MyFile" level="trace" />
+    </Root>
+  </Loggers>
+</Configuration>]]></pre>
+        </subsection>
           <a name="StandardLoggerInterface" />
           <subsection name="Convenience Methods for the Built-in Log Levels">
             <p>
@@ -107,18 +186,29 @@ debug(String, Object...)
 debug(String, Throwable)</pre>
             <p>
               Similar methods exist for the other built-in levels.
+              Custom levels, in contrast, need to pass in the log level as an extra parameter.
             </p>
+            <pre class="prettyprint">
+// need to pass the custom level as a parameter
+logger.log(VERBOSE, "a verbose message");
+logger.log(Level.forName("DIAG", 350), "another message");</pre>
             <p>It would be nice to have the same ease of use with custom levels,
-               so that after declaring a custom VERBOSE level, we could
+               so that after declaring the custom VERBOSE/DIAG levels, we could
                use code like this:
             </p>
             <pre class="prettyprint">
-logger.verbose("a verbose message"); // no need to pass the VERBOSE level as a parameter
-logger.verbose("another message");</pre>
+// nice to have: descriptive methods and no need to pass the level as a parameter
+logger.verbose("a verbose message");
+logger.diag("another message");</pre>
+            <p>The standard Logger interface cannot provide convenience methods for
+              custom levels, but the next few sections introduce a code generation tool
+              to create loggers that aim to make custom levels as easy to use
+              as built-in levels.</p>
           </subsection>
           <a name="AddingOrReplacingLevels" />
           <subsection name="Adding or Replacing Log Levels">
-            <p>In the above example, a convenience method was <em>added</em> to the Logger interface,
+            <p>
+              We assume that most users want to <em>add</em> custom level methods to the Logger interface,
                in addition to the existing trace(), debug(), info(), ... methods for the built-in log levels.
             </p>
             <p>There is another use case, Domain Specific Language loggers, where we want to <em>replace</em>