You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2022/01/28 04:28:32 UTC

[GitHub] [logging-log4j2] jvz opened a new pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

jvz opened a new pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733


   This adds a properties format feature where the property names "rootLogger" and "logger.<key>" can be set to a level and one or more appender refs.
   
   https://issues.apache.org/jira/browse/LOG4J2-3341


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] ppkarwasz commented on pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
ppkarwasz commented on pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#issuecomment-1024854364


   @jvz: #729 drops previously invalid entries like `logger.core-config-properties=INFO,app1,app2`. You should probably add a test for that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz merged pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz merged pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794221405



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       The indexed bit is how the current properties format works. I think a separate feature could be added here to automatically set the `name` attribute to the property key when otherwise absent. Note that the index here is any arbitrary prefix; I chose a number for the test.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#issuecomment-1024367931


   > @jvz: maybe you can add a default for all component names: `name = key.replaceAll("-", ".")`? This way you'll allow also to configure a logger in one property:
   > 
   > `logger.org-apache-logging-log4j=INFO,app1,app2`
   
   This is an interesting idea. The only potential issue here is that dashes are technically allowed in logger names, though I doubt they're used. Could probably be added with this whole update.
   
   I'll have docs updates to go with this before it's ready to merge.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794225556



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       I've added a way to do implicit appender names, too. As for the XML config variant, that would need to add the CompoundProperty plugin.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794226178



##########
File path: log4j-core/src/test/resources/RootLoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+status = off
+name = RootLoggerLevelAppenderTest
+rootLogger = INFO,app
+appender.app.type = List

Review comment:
       Now this properties format is getting less shitty to use, too! I like this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] rgoers commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
rgoers commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794225373



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       Matt and I only worked out how to do it for properties as that was what was requested. Doing it for XML could be possible, but it would be more difficult in YAML and JSON. I'm not even sure what the point of that would be.
   
   For XML the syntax would have to look like
   
   `<Logger name="org.apache.logging.log4j.core.config.properties" level="INFO" appenderRefs="first,second"/>`
   
   That is actually not "normal" for XML to have a list specified that way. And there would definitely be no reason to combine the level and appenderRefs into a single attribute.
   Also, looking at the Log4j1 DTD the xml had to be specified as 
   
   ```
     <root>
       <priority value ="trace" />
       <appender-ref ref="A1" />
       <appender-ref ref="A2" />
     </root>
   ```
   
   Note that the priority (which could also be specified as level) had to be an XML element whereas Log4j 2 allows it to be an element or an attribute. 
   So the bottom line is, I don't know why we would add the support to XML since it doesn't buy anything in the way of compatibility with Log4j 1.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] Apache9 commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
Apache9 commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794212770



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       Good. I think this is enough for hadoop and hbase, although it maybe a pain that we need to maintain the index. It will be easier to specify appender.first.type = List. But anyway, it works.
   
   Another question is how to specify leven and appenders at once in xml configuration file?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794647949



##########
File path: log4j-core/src/test/resources/RootLoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+status = off
+name = RootLoggerLevelAppenderTest
+rootLogger = INFO,app
+appender.app.type = List

Review comment:
       Updated.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794643584



##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");
+            loggerProps.setProperty("level", parts[0]);

Review comment:
       I think that split would result in a two value array of two empty strings.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] Apache9 commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
Apache9 commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794282859



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       OK, got it. So this is a properties file specific way.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] ppkarwasz commented on pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
ppkarwasz commented on pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#issuecomment-1023935035


   @jvz: maybe you can add a default for all component names: `name = key.replaceAll("-", ".")`? This way you'll allow also to configure a logger in one property:
   
   `logger.org-apache-logging-log4j=INFO,app1,app2`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] carterkozak commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
carterkozak commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794523439



##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");
+            loggerProps.setProperty("level", parts[0]);
+            for (int i = 1; i < parts.length; i++) {
+                loggerProps.setProperty("appenderRef.$" + i + ".ref", parts[i]);

Review comment:
       It may be worthwhile to add some StatusLogger debug logging here, I defer to your judgement :-)

##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");
+            loggerProps.setProperty("level", parts[0]);

Review comment:
       We should check that `parts` is not empty to avoid an `ArrayIndexOutOfBoundsException`. If memory serves, `",".split(",")` will result in an empty array.

##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -207,7 +221,12 @@ private ScriptFileComponentBuilder createScriptFile(final Properties properties)
     }
 
     private AppenderComponentBuilder createAppender(final String key, final Properties properties) {
-        final String name = (String) properties.remove(CONFIG_NAME);
+        final String name;
+        if (properties.containsKey(CONFIG_NAME)) {
+            name = (String) properties.remove(CONFIG_NAME);
+        } else {
+            name = key;
+        }

Review comment:
       I think we may be slightly better off retaining the original `remove` logic, only traversing the map once:
   ```suggestion
           final String name = Objects.toString(properties.remove(CONFIG_NAME), key);
   ```

##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");

Review comment:
       Do we need to trim each segment of `parts` to avoid whitespace issues? I suspect the level piece may handle it gracefully, but I'm less sure about the appenderRefs. Could be worth a test.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#issuecomment-1024803593


   I've squashed what's been reviewed. Will add more commits for docs and changelog.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794657514



##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");
+            loggerProps.setProperty("level", parts[0]);

Review comment:
       Indeed it is! I only remembered that because I checked the javadocs for `split` before using it here. At first, I was limiting the split to 1 match, but then I added the multiple refs thing.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#issuecomment-1024854475


   I have some code in PropertiesConfigurationBuilder that manually includes the invalid keys left behind.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794221405



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       The indexed bit is how the current properties format works. I think a separate feature could be added here to automatically set the `name` attribute to the property key when otherwise absent.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794645183



##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");

Review comment:
       Yes, that's a good point.
   
   - [ ] Trim appender refs




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794652735



##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");
+            loggerProps.setProperty("level", parts[0]);
+            for (int i = 1; i < parts.length; i++) {
+                loggerProps.setProperty("appenderRef.$" + i + ".ref", parts[i]);

Review comment:
       Good idea; added.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] rgoers commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
rgoers commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794225373



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       Matt and I only worked out how to do it for properties as that was what was requested. Doing it for XML could be possible, but it would be more difficult in YAML and JSON. I'm not even sure what the point of that would be.
   
   For XML the syntax would have to look like
   
   <Logger name="org.apache.logging.log4j.core.config.properties" level="INFO" appenderRefs="first,second"/>
   
   That is actually not "normal" for XML to have a list specified that way. And there would definitely be no reason to combine the level and appenderRefs into a single attribute.
   Also, looking at the Log4j1 DTD the xml had to be specified as 
   
   ```
     <root>
       <priority value ="trace" />
       <appender-ref ref="A1" />
       <appender-ref ref="A2" />
     </root>
   ```
   
   Note that the priority (which could also be specified as level) had to be an XML element whereas Log4j 2 allows it to be an element or an attribute. 
   So the bottom line is, I don't know why we would add the support to XML since it doesn't buy anything in the way of compatibility with Log4j 1.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] jvz commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794225556



##########
File path: log4j-core/src/test/resources/LoggerLevelAppenderTest.properties
##########
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+status = all
+name = LoggerLevelAppenderTest
+logger.0.name = org.apache.logging.log4j.core.config.properties
+logger.0 = INFO,first,second

Review comment:
       I've added a way to do implicit appender names, too. As for the XML config variant, there are better ways to represent that there.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [logging-log4j2] carterkozak commented on a change in pull request #733: [LOG4J2-3341] Support logger level and appender refs shorthand

Posted by GitBox <gi...@apache.org>.
carterkozak commented on a change in pull request #733:
URL: https://github.com/apache/logging-log4j2/pull/733#discussion_r794655910



##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
##########
@@ -190,6 +193,17 @@ public PropertiesConfiguration build() {
         return builder.build(false);
     }
 
+    private static void useSyntheticLevelAndAppenderRefs(final String propertyName, final Properties loggerProps, final Properties context) {
+        final String propertyValue = (String) context.remove(propertyName);
+        if (propertyValue != null) {
+            final String[] parts = propertyValue.split(",");
+            loggerProps.setProperty("level", parts[0]);

Review comment:
       It's subtle and counter-intuitive. Alas, this test passes:
   ```java
   @Test
   public void split() {
       assertThat(",".split(",")).isEmpty();
   }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org