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/27 06:39:32 UTC

[GitHub] [logging-log4j2] ppkarwasz opened a new pull request #731: Adds a Tomcat lookup

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


   The `TomcatLookup` can be used to retrieve the engine, host and context names under which the application is running. These are also provided by the original Tomcat JULI implementation (cf. [ClassLoaderLogManager#replaceWebApplicationProperties](https://github.com/apache/tomcat/blob/a05603de0fc5ae1ee60d41ea8677f96818a9b11f/java/org/apache/juli/ClassLoaderLogManager.java#L654)).
   
   It also provides three helper properties `*.logger` that resolve to the logger name used by `ServletContext#log`.


-- 
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 closed pull request #731: Adds a Tomcat lookup

Posted by GitBox <gi...@apache.org>.
ppkarwasz closed pull request #731:
URL: https://github.com/apache/logging-log4j2/pull/731


   


-- 
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] vy commented on pull request #731: Adds a Tomcat lookup

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


   I am against introducing components for 3rd party software integrations. These better be developed and maintained by the community; Log4j provides first-class extensibility mechanisms for this very reason. The core is complicated enough; there is a never-ending backlog of issues and improvements that can take the lifetime of the entire team. I think maintainers should rather focus on those.


-- 
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 a change in pull request #731: Adds a Tomcat lookup

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



##########
File path: log4j-appserver/src/main/java/org/apache/logging/log4j/appserver/tomcat/TomcatLookup.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.appserver.tomcat;
+
+import org.apache.juli.WebappProperties;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.lookup.StrLookup;
+
+/**
+ * Resolves the names specific to Tomcat's internal component structure. The
+ * names of the properties starting with {@code classloader.} are kept for
+ * compatibility with the original Tomcat JULI implementation.
+ */
+@Plugin(name = "tomcat", category = StrLookup.CATEGORY)
+public class TomcatLookup implements StrLookup {
+
+    private static final String SERVICE_LOGGER_FORMAT = "org.apache.catalina.core.ContainerBase.[%s]";
+    private static final String HOST_LOGGER_FORMAT = "org.apache.catalina.core.ContainerBase.[%s].[%s]";
+    private static final String CONTEXT_LOGGER_FORMAT = "org.apache.catalina.core.ContainerBase.[%s].[%s].[%s]";
+
+    @Override
+    public String lookup(String key) {
+        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if (cl instanceof WebappProperties) {
+            final WebappProperties props = (WebappProperties) cl;
+            switch (key) {

Review comment:
       Corrected, thanks.




-- 
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] avandeursen commented on a change in pull request #731: Adds a Tomcat lookup

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



##########
File path: log4j-appserver/src/main/java/org/apache/logging/log4j/appserver/tomcat/TomcatLookup.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.appserver.tomcat;
+
+import org.apache.juli.WebappProperties;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.lookup.StrLookup;
+
+/**
+ * Resolves the names specific to Tomcat's internal component structure. The
+ * names of the properties starting with {@code classloader.} are kept for
+ * compatibility with the original Tomcat JULI implementation.
+ */
+@Plugin(name = "tomcat", category = StrLookup.CATEGORY)
+public class TomcatLookup implements StrLookup {
+
+    private static final String SERVICE_LOGGER_FORMAT = "org.apache.catalina.core.ContainerBase.[%s]";
+    private static final String HOST_LOGGER_FORMAT = "org.apache.catalina.core.ContainerBase.[%s].[%s]";
+    private static final String CONTEXT_LOGGER_FORMAT = "org.apache.catalina.core.ContainerBase.[%s].[%s].[%s]";
+
+    @Override
+    public String lookup(String key) {
+        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if (cl instanceof WebappProperties) {
+            final WebappProperties props = (WebappProperties) cl;
+            switch (key) {

Review comment:
       The `StrLookup` interface explicitly allows the `key` parameter of the `lookup` method to be null. This would trigger a `NullPointerException` here. Perhaps add a condition to check that `key != null`?




-- 
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