Repository: logging-log4j2
Updated Branches:
  refs/heads/master 0091f1a93 -> 12715841a


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/master
Commit: 5427dea87da1ce36f1a740beea0e6470e1c856bf
Parents: e4a9d7f
Author: rpopma <[email protected]>
Authored: Thu Sep 25 00:49:46 2014 +0900
Committer: rpopma <[email protected]>
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;
+    }
+}

Reply via email to