In org.apache.logging.log4j.appserver.jetty.Log4j2Logger.PrivateManager.getContext():
Is this just a matter of changing false to true in: public static LoggerContext getContext() { final ClassLoader cl = Log4j2Logger.class.getClassLoader(); return getContext(FQCN, cl, false); } Or is the method supposed to dig up a class loader from a application class on the stack? ? Gary On Mon, Nov 13, 2017 at 9:21 AM, Gary Gregory <garydgreg...@gmail.com> wrote: > I will take a look... > > On Nov 13, 2017 08:43, "Ralph Goers" <ralph.go...@dslextreme.com> wrote: > >> Are you planning on fixing this? >> >> Ralph >> >> > On Nov 11, 2017, at 5:15 PM, Ralph Goers <ralph.go...@dslextreme.com> >> wrote: >> > >> > Because the caller of newLogger(name) is AbstractLogger its ClassLoader >> will always be used. You need the ClassLoader of the caller of getLogger(). >> > >> > Ralph >> > >> >> On Nov 11, 2017, at 3:43 PM, Gary Gregory <garydgreg...@gmail.com> >> wrote: >> >> >> >> Please code review git master. I'm not sure I have the class loader >> right. >> >> >> >> Gary >> >> >> >> On Sat, Nov 11, 2017 at 2:54 PM, Ralph Goers < >> ralph.go...@dslextreme.com> >> >> wrote: >> >> >> >>> Oh, but you probably don’t want to extend AbstractLogger. You really >> want >> >>> the FQCN of the caller to be able to identify the ClassLoader and >> >>> LoggerContext to use and you won’t get that from AbstractLogger’s >> getLogger >> >>> method. >> >>> >> >>> Ralph >> >>> >> >>>> On Nov 11, 2017, at 2:45 PM, Ralph Goers <ralph.go...@dslextreme.com >> > >> >>> wrote: >> >>>> >> >>>> Sure. Look at TomcatLogger. It does exactly what you are trying to >> do. >> >>>> >> >>>> Ralph >> >>>> >> >>>>> On Nov 11, 2017, at 2:02 PM, Gary Gregory <garydgreg...@gmail.com> >> >>> wrote: >> >>>>> >> >>>>> The Javadoc for Log4j's LoggerAdapter says "This registry should >> not be >> >>>>> used for Log4j Loggers; it is instead used for creating bridges to >> other >> >>>>> external log systems.". >> >>>>> >> >>>>> In this case we are not bridging TO another log system. We are >> plugging >> >>>>> INTO Jetty's log system and subclassing Jetty's own LoggerAdapter >> class >> >>>>> (out convenience.) >> >>>>> >> >>>>> Further thoughts? >> >>>>> >> >>>>> Gary >> >>>>> >> >>>>> On Fri, Nov 10, 2017 at 9:25 PM, Matt Sicker <boa...@gmail.com> >> wrote: >> >>>>> >> >>>>>> IIRC, the easiest way to support it might be to use >> >>>>>> https://logging.apache.org/log4j/2.x/log4j-api/apidocs/ >> >>>>>> org/apache/logging/log4j/spi/AbstractLoggerAdapter.html >> >>>>>> >> >>>>>> On 10 November 2017 at 22:16, Gary Gregory <garydgreg...@gmail.com >> > >> >>> wrote: >> >>>>>> >> >>>>>>> I think you are correct... >> >>>>>>> >> >>>>>>> Gary >> >>>>>>> >> >>>>>>> On Fri, Nov 10, 2017 at 6:59 PM, Matt Sicker <boa...@gmail.com> >> >>> wrote: >> >>>>>>> >> >>>>>>>> Wouldn't this implementation contain incorrect caller location >> >>>>>>> information? >> >>>>>>>> >> >>>>>>>> On 10 November 2017 at 19:25, <ggreg...@apache.org> wrote: >> >>>>>>>> >> >>>>>>>>> Repository: logging-log4j2 >> >>>>>>>>> Updated Branches: >> >>>>>>>>> refs/heads/master aad2f132b -> 7d52f131e >> >>>>>>>>> >> >>>>>>>>> >> >>>>>>>>> [LOG4J2-2114] Provide a native Log4j 2 implementation of Eclipse >> >>>>>>> Jetty's >> >>>>>>>>> org.eclipse.jetty.util.log.Logger. >> >>>>>>>>> >> >>>>>>>>> Project: http://git-wip-us.apache.org/r >> epos/asf/logging-log4j2/repo >> >>>>>>>>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/ >> >>>>>>>>> commit/7d52f131 >> >>>>>>>>> Tree: http://git-wip-us.apache.org/r >> epos/asf/logging-log4j2/tree/ >> >>>>>>>> 7d52f131 >> >>>>>>>>> Diff: http://git-wip-us.apache.org/r >> epos/asf/logging-log4j2/diff/ >> >>>>>>>> 7d52f131 >> >>>>>>>>> >> >>>>>>>>> Branch: refs/heads/master >> >>>>>>>>> Commit: 7d52f131ec1e000834bcb40343f3f2d41805c75a >> >>>>>>>>> Parents: aad2f13 >> >>>>>>>>> Author: Gary Gregory <ggreg...@apache.org> >> >>>>>>>>> Authored: Fri Nov 10 18:25:47 2017 -0700 >> >>>>>>>>> Committer: Gary Gregory <ggreg...@apache.org> >> >>>>>>>>> Committed: Fri Nov 10 18:25:47 2017 -0700 >> >>>>>>>>> >> >>>>>>>>> ------------------------------------------------------------ >> >>>>>> ---------- >> >>>>>>>>> log4j-appserver/pom.xml | 8 + >> >>>>>>>>> .../log4j/appserver/jetty/Log4j2Logger.java | 184 >> >>>>>>>> +++++++++++++++++++ >> >>>>>>>>> src/changes/changes.xml | 3 + >> >>>>>>>>> 3 files changed, 195 insertions(+) >> >>>>>>>>> ------------------------------------------------------------ >> >>>>>> ---------- >> >>>>>>>>> >> >>>>>>>>> >> >>>>>>>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ >> >>>>>>>>> 7d52f131/log4j-appserver/pom.xml >> >>>>>>>>> ------------------------------------------------------------ >> >>>>>> ---------- >> >>>>>>>>> diff --git a/log4j-appserver/pom.xml b/log4j-appserver/pom.xml >> >>>>>>>>> index e96b1fc..6acd77b 100644 >> >>>>>>>>> --- a/log4j-appserver/pom.xml >> >>>>>>>>> +++ b/log4j-appserver/pom.xml >> >>>>>>>>> @@ -34,6 +34,7 @@ >> >>>>>>>>> <docLabel>Web Documentation</docLabel> >> >>>>>>>>> <projectDir>/log4j-appserver</projectDir> >> >>>>>>>>> <tomcat.version>8.5.20</tomcat.version> >> >>>>>>>>> + <jetty.version>8.2.0.v20160908</jetty.version> <!-- >> Jetty 9 >> >>>>>>>>> requires Java 8 --> >> >>>>>>>>> <module.name>org.apache.logging.log4j.appserver</module.name> >> >>>>>>>>> </properties> >> >>>>>>>>> >> >>>>>>>>> @@ -56,6 +57,7 @@ >> >>>>>>>>> <groupId>org.apache.tomcat</groupId> >> >>>>>>>>> <artifactId>tomcat-catalina</artifactId> >> >>>>>>>>> <version>${tomcat.version}</version> >> >>>>>>>>> + <scope>provided</scope> >> >>>>>>>>> <exclusions> >> >>>>>>>>> <exclusion> >> >>>>>>>>> <groupId>org.apache.tomcat</groupId> >> >>>>>>>>> @@ -71,6 +73,12 @@ >> >>>>>>>>> </exclusion> >> >>>>>>>>> </exclusions> >> >>>>>>>>> </dependency> >> >>>>>>>>> + <dependency> >> >>>>>>>>> + <groupId>org.eclipse.jetty</groupId> >> >>>>>>>>> + <artifactId>jetty-util</artifactId> >> >>>>>>>>> + <version>${jetty.version}</version> >> >>>>>>>>> + <scope>provided</scope> >> >>>>>>>>> + </dependency> >> >>>>>>>>> >> >>>>>>>>> <!-- Test dependencies --> >> >>>>>>>>> <dependency> >> >>>>>>>>> >> >>>>>>>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ >> >>>>>>>>> 7d52f131/log4j-appserver/src/main/java/org/apache/logging/ >> >>>>>>>>> log4j/appserver/jetty/Log4j2Logger.java >> >>>>>>>>> ------------------------------------------------------------ >> >>>>>> ---------- >> >>>>>>>>> diff --git a/log4j-appserver/src/main/ >> >>> java/org/apache/logging/log4j/ >> >>>>>>>>> appserver/jetty/Log4j2Logger.java b/log4j-appserver/src/main/ >> >>>>>>>>> java/org/apache/logging/log4j/appserver/jetty/Log4j2Logger.java >> >>>>>>>>> new file mode 100644 >> >>>>>>>>> index 0000000..7d1ce14 >> >>>>>>>>> --- /dev/null >> >>>>>>>>> +++ b/log4j-appserver/src/main/java/org/apache/logging/log4j/ >> >>>>>>>>> appserver/jetty/Log4j2Logger.java >> >>>>>>>>> @@ -0,0 +1,184 @@ >> >>>>>>>>> +/* >> >>>>>>>>> + * 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.jetty; >> >>>>>>>>> + >> >>>>>>>>> +import org.apache.logging.log4j.LogManager; >> >>>>>>>>> +import org.eclipse.jetty.util.log.AbstractLogger; >> >>>>>>>>> +import org.eclipse.jetty.util.log.Logger; >> >>>>>>>>> + >> >>>>>>>>> +/** >> >>>>>>>>> + * Provides a native Apache Log4j 2 for Jetty logging. >> >>>>>>>>> + */ >> >>>>>>>>> +public class Log4j2Logger extends AbstractLogger { >> >>>>>>>>> + >> >>>>>>>>> + private final org.apache.logging.log4j.Logger logger; >> >>>>>>>>> + >> >>>>>>>>> + private final String name; >> >>>>>>>>> + >> >>>>>>>>> + public Log4j2Logger(final String name) { >> >>>>>>>>> + super(); >> >>>>>>>>> + this.name = name; >> >>>>>>>>> + this.logger = LogManager.getLogger(name); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + public Log4j2Logger() { >> >>>>>>>>> + this(""); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log. >> >>>>>> Logger#debug(java.lang.String, >> >>>>>>>>> java.lang.Object[]) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void debug(final String msg, final Object... args) { >> >>>>>>>>> + logger.debug(msg, args); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log. >> >>>>>> Logger#debug(java.lang.String, >> >>>>>>>>> java.lang.Throwable) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void debug(final String msg, final Throwable >> thrown) { >> >>>>>>>>> + logger.debug(msg, thrown); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log.Logger#debug(java.lang. >> >>>>>>>> Throwable) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void debug(final Throwable thrown) { >> >>>>>>>>> + logger.debug(thrown); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log.Logger#getName() >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public String getName() { >> >>>>>>>>> + return name; >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log.Log >> ger#ignore(java.lang. >> >>>>>>>> Throwable) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void ignore(final Throwable ignored) { >> >>>>>>>>> + // TODO Auto-generated method stub >> >>>>>>>>> + >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log. >> >>>>>> Logger#info(java.lang.String, >> >>>>>>>>> java.lang.Object[]) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void info(final String msg, final Object... args) { >> >>>>>>>>> + logger.info(msg, args); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log. >> >>>>>> Logger#info(java.lang.String, >> >>>>>>>>> java.lang.Throwable) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void info(final String msg, final Throwable thrown) >> { >> >>>>>>>>> + logger.info(msg, thrown); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log.Logger#info(java.lang. >> >>>>>>> Throwable) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void info(final Throwable thrown) { >> >>>>>>>>> + logger.info(thrown); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log.Logger#isDebugEnabled() >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public boolean isDebugEnabled() { >> >>>>>>>>> + return logger.isDebugEnabled(); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log. >> >>>>>> AbstractLogger#newLogger(java. >> >>>>>>>>> lang.String) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + protected Logger newLogger(final String fullname) { >> >>>>>>>>> + return new Log4j2Logger(fullname); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log.Logger#setDebugEnabled( >> >>>>>>> boolean) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void setDebugEnabled(final boolean enabled) { >> >>>>>>>>> + warn("setDebugEnabled not implemented"); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log. >> >>>>>> Logger#warn(java.lang.String, >> >>>>>>>>> java.lang.Object[]) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void warn(final String msg, final Object... args) { >> >>>>>>>>> + logger.warn(msg, args); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log. >> >>>>>> Logger#warn(java.lang.String, >> >>>>>>>>> java.lang.Throwable) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void warn(final String msg, final Throwable thrown) >> { >> >>>>>>>>> + logger.warn(msg, thrown); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> + /* >> >>>>>>>>> + * (non-Javadoc) >> >>>>>>>>> + * >> >>>>>>>>> + * @see org.eclipse.jetty.util.log.Logger#warn(java.lang. >> >>>>>>> Throwable) >> >>>>>>>>> + */ >> >>>>>>>>> + @Override >> >>>>>>>>> + public void warn(final Throwable thrown) { >> >>>>>>>>> + logger.warn(thrown); >> >>>>>>>>> + } >> >>>>>>>>> + >> >>>>>>>>> +} >> >>>>>>>>> >> >>>>>>>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ >> >>>>>>>>> 7d52f131/src/changes/changes.xml >> >>>>>>>>> ------------------------------------------------------------ >> >>>>>> ---------- >> >>>>>>>>> diff --git a/src/changes/changes.xml b/src/changes/changes.xml >> >>>>>>>>> index 2bcefb2..070e4a1 100644 >> >>>>>>>>> --- a/src/changes/changes.xml >> >>>>>>>>> +++ b/src/changes/changes.xml >> >>>>>>>>> @@ -37,6 +37,9 @@ >> >>>>>>>>> <action issue="LOG4J2-2103" dev="mikes" type="add"> >> >>>>>>>>> XML encoding for PatternLayout. >> >>>>>>>>> </action> >> >>>>>>>>> + <action issue="LOG4J2-2114" dev="ggregory" type="add"> >> >>>>>>>>> + Provide a native Log4j 2 implementation of Eclipse >> Jetty's >> >>>>>>>>> org.eclipse.jetty.util.log.Logger. >> >>>>>>>>> + </action> >> >>>>>>>>> <action issue="LOG4J2-1203" dev="mikes" type="add" >> >>>>>>> due-to="Robert >> >>>>>>>>> Turner"> >> >>>>>>>>> Allow filtering of line breaks in layout pattern. >> >>>>>>>>> </action> >> >>>>>>>>> >> >>>>>>>>> >> >>>>>>>> >> >>>>>>>> >> >>>>>>>> -- >> >>>>>>>> Matt Sicker <boa...@gmail.com> >> >>>>>>>> >> >>>>>>> >> >>>>>> >> >>>>>> >> >>>>>> >> >>>>>> -- >> >>>>>> Matt Sicker <boa...@gmail.com> >> >>>>>> >> >>>> >> >>>> >> >>>> >> >>> >> >>> >> >>> >> > >> > >> > >> >> >>