You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/22 01:09:12 UTC

[1/4] git commit: Small simplification in getClassLoader(Class, Class).

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 9fa90c716 -> cb631914c


Small simplification in getClassLoader(Class,Class).

  - LoaderUtil.getThreadContextClassLoader() will not throw an
  exception.


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

Branch: refs/heads/master
Commit: 0e5cc42dc3ba2b6a24d52637ad914ccf573be76c
Parents: 9fa90c7
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 16:50:06 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 16:50:06 2014 -0500

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/util/Loader.java     | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0e5cc42d/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
index 9858d4e..6661568 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
@@ -56,6 +56,7 @@ public final class Loader {
      * available.
      *
      * @return the TCCL.
+     * @see org.apache.logging.log4j.util.LoaderUtil#getThreadContextClassLoader()
      */
     public static ClassLoader getThreadContextClassLoader() {
         return LoaderUtil.getThreadContextClassLoader();
@@ -63,13 +64,7 @@ public final class Loader {
 
     // TODO: this method could use some explanation
     public static ClassLoader getClassLoader(final Class<?> class1, final Class<?> class2) {
-
-        ClassLoader threadContextClassLoader = null;
-        try {
-            threadContextClassLoader = getTcl();
-        } catch (final Exception ex) {
-            LOGGER.warn("Caught exception locating thread ClassLoader {}", ex.getMessage());
-        }
+        final ClassLoader threadContextClassLoader = getTcl();
         final ClassLoader loader1 = class1 == null ? null : class1.getClassLoader();
         final ClassLoader loader2 = class2 == null ? null : class2.getClassLoader();
 


Re: [2/4] git commit: Doc update regarding how servlet contexts can be named.

Posted by Matt Sicker <bo...@gmail.com>.
WebLogic and WebSphere come to mind, particularly when trying to use log4j
in the server lib instead of just a war.

On 21 September 2014 19:51, Remko Popma <re...@gmail.com> wrote:

> I see.
> My 2c: we have documented the current behaviour and haven't had any
> complaints so there's not much reason to change it. This error, if it
> happens, happens at deploy time so the users will very likely notice & take
> action. We could change this to just log the error, I'd be fine with that
> too. (I do hope it's not a lot of work or results in complex code.)
>
> Different question: what exotic web containers and why does log4j-web need
> to be more flexible?
>
> Sent from my iPhone
>
> On 2014/09/22, at 9:02, Matt Sicker <bo...@gmail.com> wrote:
>
> Well, as it is now, if this fails, everything fails (until an exception is
> caught or the main method lets it go). I could probably modify this to not
> fail like that if it can't initialize and just fall back to the default
> configuration and such like we normally do. I'm currently refactoring
> log4j-web quite a bit to make it more flexible in exotic servlet containers
> and such where custom programmatic configuration may be required (i.e., set
> up a ConfigurationSource with a custom class).
>
> On 21 September 2014 18:37, Remko Popma <re...@gmail.com> wrote:
>
>> In other places the log4j policy is that logging config errors or errors
>> during logging should not impact the application unless the user asked for
>> it (as in audit logging).
>>
>> So, logging the error would be consistent with that. On the other hand we
>> haven't had any complaints...
>>
>> If this fails though, would calls to logger methods be silently ignored
>> or what would happen?
>> (Is it even possible to log the problem and keep on truckin'? )
>>
>> Sent from my iPhone
>>
>> On 2014/09/22, at 8:28, Matt Sicker <bo...@gmail.com> wrote:
>>
>> Well, the way the code currently is written, it looks like it does indeed
>> throw an exception which would propagate upward to the
>> ServletContextListener or ServletContainerListener, so it's still correct.
>> Perhaps it shouldn't actually do that and just log an error?
>>
>> On 21 September 2014 18:22, Remko Popma <re...@gmail.com> wrote:
>>
>>> The docs say
>>> > otherwise, the application will fail to start with an exception.
>>>
>>> Is this true? Or should that be ...logging will fail to start with an
>>> exception.
>>>
>>> Sent from my iPhone
>>>
>>> > On 2014/09/22, at 8:09, mattsicker@apache.org wrote:
>>> >
>>> > Doc update regarding how servlet contexts can be named.
>>> >
>>> >
>>> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>> > Commit:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3c868456
>>> > Tree:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3c868456
>>> > Diff:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3c868456
>>> >
>>> > Branch: refs/heads/master
>>> > Commit: 3c868456ed043673a889cdcd0afe3513a695dd72
>>> > Parents: 0e5cc42
>>> > Author: Matt Sicker <ma...@apache.org>
>>> > Authored: Sun Sep 21 17:21:07 2014 -0500
>>> > Committer: Matt Sicker <ma...@apache.org>
>>> > Committed: Sun Sep 21 17:21:07 2014 -0500
>>> >
>>> > ----------------------------------------------------------------------
>>> > src/site/xdoc/manual/webapp.xml | 12 +++++++-----
>>> > 1 file changed, 7 insertions(+), 5 deletions(-)
>>> > ----------------------------------------------------------------------
>>> >
>>> >
>>> >
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c868456/src/site/xdoc/manual/webapp.xml
>>> > ----------------------------------------------------------------------
>>> > diff --git a/src/site/xdoc/manual/webapp.xml
>>> b/src/site/xdoc/manual/webapp.xml
>>> > index ecad1f9..1b86d45 100644
>>> > --- a/src/site/xdoc/manual/webapp.xml
>>> > +++ b/src/site/xdoc/manual/webapp.xml
>>> > @@ -177,17 +177,19 @@
>>> >       <subsection name="Context Parameters">
>>> >         <a name="ContextParams" />
>>> >         <p>
>>> > -          By default, Log4j 2 uses the <code>ServletContext</code>'s
>>> context name as the <code>LoggerContext</code> name
>>> > -          and uses the standard pattern for locating the Log4j
>>> configuration file. There are three context parameters
>>> > -          that you can use to control this behavior. The first,
>>> <code>isLog4jContextSelectorNamed</code>, specifies
>>> > -          whether the context should be selected using the
>>> > +          By default, Log4j 2 uses the <code>ServletContext</code>'s
>>> > +          <a href="
>>> http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getServletContextName()">context
>>> name</a>
>>> > +          as the <code>LoggerContext</code> name and uses the
>>> standard pattern for locating the Log4j configuration
>>> > +          file. There are three context parameters that you can use
>>> to control this behavior. The first,
>>> > +          <code>isLog4jContextSelectorNamed</code>, specifies whether
>>> the context should be selected using the
>>> >           <a class="javadoc"
>>> href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
>>> >> JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code>
>>> is not specified or is anything other
>>> >           than <code>true</code>, it is assumed to be
>>> <code>false</code>.
>>> >         </p>
>>> >         <p>
>>> >           If <code>isLog4jContextSelectorNamed</code> is
>>> <code>true</code>, <code>log4jContextName</code> must be
>>> > -          specified; otherwise, the application will fail to start
>>> with an exception. <code>log4jConfiguration</code>
>>> > +          specified or <code>display-name</code> must be specified in
>>> <code>web.xml</code>; otherwise, the application
>>> > +          will fail to start with an exception.
>>> <code>log4jConfiguration</code>
>>> >           <em>should</em> also be specified in this case, and must be
>>> a valid URI for the configuration file; however,
>>> >           this parameter is not required.
>>> >         </p>
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>>>
>>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
>


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

Re: [2/4] git commit: Doc update regarding how servlet contexts can be named.

Posted by Remko Popma <re...@gmail.com>.
I see. 
My 2c: we have documented the current behaviour and haven't had any complaints so there's not much reason to change it. This error, if it happens, happens at deploy time so the users will very likely notice & take action. We could change this to just log the error, I'd be fine with that too. (I do hope it's not a lot of work or results in complex code.)

Different question: what exotic web containers and why does log4j-web need to be more flexible?

Sent from my iPhone

> On 2014/09/22, at 9:02, Matt Sicker <bo...@gmail.com> wrote:
> 
> Well, as it is now, if this fails, everything fails (until an exception is caught or the main method lets it go). I could probably modify this to not fail like that if it can't initialize and just fall back to the default configuration and such like we normally do. I'm currently refactoring log4j-web quite a bit to make it more flexible in exotic servlet containers and such where custom programmatic configuration may be required (i.e., set up a ConfigurationSource with a custom class).
> 
>> On 21 September 2014 18:37, Remko Popma <re...@gmail.com> wrote:
>> In other places the log4j policy is that logging config errors or errors during logging should not impact the application unless the user asked for it (as in audit logging). 
>> 
>> So, logging the error would be consistent with that. On the other hand we haven't had any complaints...
>> 
>> If this fails though, would calls to logger methods be silently ignored or what would happen? 
>> (Is it even possible to log the problem and keep on truckin'? )
>> 
>> Sent from my iPhone
>> 
>>> On 2014/09/22, at 8:28, Matt Sicker <bo...@gmail.com> wrote:
>>> 
>>> Well, the way the code currently is written, it looks like it does indeed throw an exception which would propagate upward to the ServletContextListener or ServletContainerListener, so it's still correct. Perhaps it shouldn't actually do that and just log an error?
>>> 
>>>> On 21 September 2014 18:22, Remko Popma <re...@gmail.com> wrote:
>>>> The docs say
>>>> > otherwise, the application will fail to start with an exception.
>>>> 
>>>> Is this true? Or should that be ...logging will fail to start with an exception.
>>>> 
>>>> Sent from my iPhone
>>>> 
>>>> > On 2014/09/22, at 8:09, mattsicker@apache.org wrote:
>>>> >
>>>> > Doc update regarding how servlet contexts can be named.
>>>> >
>>>> >
>>>> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>>> > Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3c868456
>>>> > Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3c868456
>>>> > Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3c868456
>>>> >
>>>> > Branch: refs/heads/master
>>>> > Commit: 3c868456ed043673a889cdcd0afe3513a695dd72
>>>> > Parents: 0e5cc42
>>>> > Author: Matt Sicker <ma...@apache.org>
>>>> > Authored: Sun Sep 21 17:21:07 2014 -0500
>>>> > Committer: Matt Sicker <ma...@apache.org>
>>>> > Committed: Sun Sep 21 17:21:07 2014 -0500
>>>> >
>>>> > ----------------------------------------------------------------------
>>>> > src/site/xdoc/manual/webapp.xml | 12 +++++++-----
>>>> > 1 file changed, 7 insertions(+), 5 deletions(-)
>>>> > ----------------------------------------------------------------------
>>>> >
>>>> >
>>>> > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c868456/src/site/xdoc/manual/webapp.xml
>>>> > ----------------------------------------------------------------------
>>>> > diff --git a/src/site/xdoc/manual/webapp.xml b/src/site/xdoc/manual/webapp.xml
>>>> > index ecad1f9..1b86d45 100644
>>>> > --- a/src/site/xdoc/manual/webapp.xml
>>>> > +++ b/src/site/xdoc/manual/webapp.xml
>>>> > @@ -177,17 +177,19 @@
>>>> >       <subsection name="Context Parameters">
>>>> >         <a name="ContextParams" />
>>>> >         <p>
>>>> > -          By default, Log4j 2 uses the <code>ServletContext</code>'s context name as the <code>LoggerContext</code> name
>>>> > -          and uses the standard pattern for locating the Log4j configuration file. There are three context parameters
>>>> > -          that you can use to control this behavior. The first, <code>isLog4jContextSelectorNamed</code>, specifies
>>>> > -          whether the context should be selected using the
>>>> > +          By default, Log4j 2 uses the <code>ServletContext</code>'s
>>>> > +          <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getServletContextName()">context name</a>
>>>> > +          as the <code>LoggerContext</code> name and uses the standard pattern for locating the Log4j configuration
>>>> > +          file. There are three context parameters that you can use to control this behavior. The first,
>>>> > +          <code>isLog4jContextSelectorNamed</code>, specifies whether the context should be selected using the
>>>> >           <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
>>>> >> JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code> is not specified or is anything other
>>>> >           than <code>true</code>, it is assumed to be <code>false</code>.
>>>> >         </p>
>>>> >         <p>
>>>> >           If <code>isLog4jContextSelectorNamed</code> is <code>true</code>, <code>log4jContextName</code> must be
>>>> > -          specified; otherwise, the application will fail to start with an exception. <code>log4jConfiguration</code>
>>>> > +          specified or <code>display-name</code> must be specified in <code>web.xml</code>; otherwise, the application
>>>> > +          will fail to start with an exception. <code>log4jConfiguration</code>
>>>> >           <em>should</em> also be specified in this case, and must be a valid URI for the configuration file; however,
>>>> >           this parameter is not required.
>>>> >         </p>
>>>> >
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>>> 
>>> 
>>> 
>>> -- 
>>> Matt Sicker <bo...@gmail.com>
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>

Re: [2/4] git commit: Doc update regarding how servlet contexts can be named.

Posted by Matt Sicker <bo...@gmail.com>.
Well, as it is now, if this fails, everything fails (until an exception is
caught or the main method lets it go). I could probably modify this to not
fail like that if it can't initialize and just fall back to the default
configuration and such like we normally do. I'm currently refactoring
log4j-web quite a bit to make it more flexible in exotic servlet containers
and such where custom programmatic configuration may be required (i.e., set
up a ConfigurationSource with a custom class).

On 21 September 2014 18:37, Remko Popma <re...@gmail.com> wrote:

> In other places the log4j policy is that logging config errors or errors
> during logging should not impact the application unless the user asked for
> it (as in audit logging).
>
> So, logging the error would be consistent with that. On the other hand we
> haven't had any complaints...
>
> If this fails though, would calls to logger methods be silently ignored or
> what would happen?
> (Is it even possible to log the problem and keep on truckin'? )
>
> Sent from my iPhone
>
> On 2014/09/22, at 8:28, Matt Sicker <bo...@gmail.com> wrote:
>
> Well, the way the code currently is written, it looks like it does indeed
> throw an exception which would propagate upward to the
> ServletContextListener or ServletContainerListener, so it's still correct.
> Perhaps it shouldn't actually do that and just log an error?
>
> On 21 September 2014 18:22, Remko Popma <re...@gmail.com> wrote:
>
>> The docs say
>> > otherwise, the application will fail to start with an exception.
>>
>> Is this true? Or should that be ...logging will fail to start with an
>> exception.
>>
>> Sent from my iPhone
>>
>> > On 2014/09/22, at 8:09, mattsicker@apache.org wrote:
>> >
>> > Doc update regarding how servlet contexts can be named.
>> >
>> >
>> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> > Commit:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3c868456
>> > Tree:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3c868456
>> > Diff:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3c868456
>> >
>> > Branch: refs/heads/master
>> > Commit: 3c868456ed043673a889cdcd0afe3513a695dd72
>> > Parents: 0e5cc42
>> > Author: Matt Sicker <ma...@apache.org>
>> > Authored: Sun Sep 21 17:21:07 2014 -0500
>> > Committer: Matt Sicker <ma...@apache.org>
>> > Committed: Sun Sep 21 17:21:07 2014 -0500
>> >
>> > ----------------------------------------------------------------------
>> > src/site/xdoc/manual/webapp.xml | 12 +++++++-----
>> > 1 file changed, 7 insertions(+), 5 deletions(-)
>> > ----------------------------------------------------------------------
>> >
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c868456/src/site/xdoc/manual/webapp.xml
>> > ----------------------------------------------------------------------
>> > diff --git a/src/site/xdoc/manual/webapp.xml
>> b/src/site/xdoc/manual/webapp.xml
>> > index ecad1f9..1b86d45 100644
>> > --- a/src/site/xdoc/manual/webapp.xml
>> > +++ b/src/site/xdoc/manual/webapp.xml
>> > @@ -177,17 +177,19 @@
>> >       <subsection name="Context Parameters">
>> >         <a name="ContextParams" />
>> >         <p>
>> > -          By default, Log4j 2 uses the <code>ServletContext</code>'s
>> context name as the <code>LoggerContext</code> name
>> > -          and uses the standard pattern for locating the Log4j
>> configuration file. There are three context parameters
>> > -          that you can use to control this behavior. The first,
>> <code>isLog4jContextSelectorNamed</code>, specifies
>> > -          whether the context should be selected using the
>> > +          By default, Log4j 2 uses the <code>ServletContext</code>'s
>> > +          <a href="
>> http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getServletContextName()">context
>> name</a>
>> > +          as the <code>LoggerContext</code> name and uses the standard
>> pattern for locating the Log4j configuration
>> > +          file. There are three context parameters that you can use to
>> control this behavior. The first,
>> > +          <code>isLog4jContextSelectorNamed</code>, specifies whether
>> the context should be selected using the
>> >           <a class="javadoc"
>> href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
>> >> JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code>
>> is not specified or is anything other
>> >           than <code>true</code>, it is assumed to be
>> <code>false</code>.
>> >         </p>
>> >         <p>
>> >           If <code>isLog4jContextSelectorNamed</code> is
>> <code>true</code>, <code>log4jContextName</code> must be
>> > -          specified; otherwise, the application will fail to start
>> with an exception. <code>log4jConfiguration</code>
>> > +          specified or <code>display-name</code> must be specified in
>> <code>web.xml</code>; otherwise, the application
>> > +          will fail to start with an exception.
>> <code>log4jConfiguration</code>
>> >           <em>should</em> also be specified in this case, and must be a
>> valid URI for the configuration file; however,
>> >           this parameter is not required.
>> >         </p>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
>


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

Re: [2/4] git commit: Doc update regarding how servlet contexts can be named.

Posted by Remko Popma <re...@gmail.com>.
In other places the log4j policy is that logging config errors or errors during logging should not impact the application unless the user asked for it (as in audit logging). 

So, logging the error would be consistent with that. On the other hand we haven't had any complaints...

If this fails though, would calls to logger methods be silently ignored or what would happen? 
(Is it even possible to log the problem and keep on truckin'? )

Sent from my iPhone

> On 2014/09/22, at 8:28, Matt Sicker <bo...@gmail.com> wrote:
> 
> Well, the way the code currently is written, it looks like it does indeed throw an exception which would propagate upward to the ServletContextListener or ServletContainerListener, so it's still correct. Perhaps it shouldn't actually do that and just log an error?
> 
>> On 21 September 2014 18:22, Remko Popma <re...@gmail.com> wrote:
>> The docs say
>> > otherwise, the application will fail to start with an exception.
>> 
>> Is this true? Or should that be ...logging will fail to start with an exception.
>> 
>> Sent from my iPhone
>> 
>> > On 2014/09/22, at 8:09, mattsicker@apache.org wrote:
>> >
>> > Doc update regarding how servlet contexts can be named.
>> >
>> >
>> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> > Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3c868456
>> > Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3c868456
>> > Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3c868456
>> >
>> > Branch: refs/heads/master
>> > Commit: 3c868456ed043673a889cdcd0afe3513a695dd72
>> > Parents: 0e5cc42
>> > Author: Matt Sicker <ma...@apache.org>
>> > Authored: Sun Sep 21 17:21:07 2014 -0500
>> > Committer: Matt Sicker <ma...@apache.org>
>> > Committed: Sun Sep 21 17:21:07 2014 -0500
>> >
>> > ----------------------------------------------------------------------
>> > src/site/xdoc/manual/webapp.xml | 12 +++++++-----
>> > 1 file changed, 7 insertions(+), 5 deletions(-)
>> > ----------------------------------------------------------------------
>> >
>> >
>> > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c868456/src/site/xdoc/manual/webapp.xml
>> > ----------------------------------------------------------------------
>> > diff --git a/src/site/xdoc/manual/webapp.xml b/src/site/xdoc/manual/webapp.xml
>> > index ecad1f9..1b86d45 100644
>> > --- a/src/site/xdoc/manual/webapp.xml
>> > +++ b/src/site/xdoc/manual/webapp.xml
>> > @@ -177,17 +177,19 @@
>> >       <subsection name="Context Parameters">
>> >         <a name="ContextParams" />
>> >         <p>
>> > -          By default, Log4j 2 uses the <code>ServletContext</code>'s context name as the <code>LoggerContext</code> name
>> > -          and uses the standard pattern for locating the Log4j configuration file. There are three context parameters
>> > -          that you can use to control this behavior. The first, <code>isLog4jContextSelectorNamed</code>, specifies
>> > -          whether the context should be selected using the
>> > +          By default, Log4j 2 uses the <code>ServletContext</code>'s
>> > +          <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getServletContextName()">context name</a>
>> > +          as the <code>LoggerContext</code> name and uses the standard pattern for locating the Log4j configuration
>> > +          file. There are three context parameters that you can use to control this behavior. The first,
>> > +          <code>isLog4jContextSelectorNamed</code>, specifies whether the context should be selected using the
>> >           <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
>> >> JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code> is not specified or is anything other
>> >           than <code>true</code>, it is assumed to be <code>false</code>.
>> >         </p>
>> >         <p>
>> >           If <code>isLog4jContextSelectorNamed</code> is <code>true</code>, <code>log4jContextName</code> must be
>> > -          specified; otherwise, the application will fail to start with an exception. <code>log4jConfiguration</code>
>> > +          specified or <code>display-name</code> must be specified in <code>web.xml</code>; otherwise, the application
>> > +          will fail to start with an exception. <code>log4jConfiguration</code>
>> >           <em>should</em> also be specified in this case, and must be a valid URI for the configuration file; however,
>> >           this parameter is not required.
>> >         </p>
>> >
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>

Re: [2/4] git commit: Doc update regarding how servlet contexts can be named.

Posted by Matt Sicker <bo...@gmail.com>.
Well, the way the code currently is written, it looks like it does indeed
throw an exception which would propagate upward to the
ServletContextListener or ServletContainerListener, so it's still correct.
Perhaps it shouldn't actually do that and just log an error?

On 21 September 2014 18:22, Remko Popma <re...@gmail.com> wrote:

> The docs say
> > otherwise, the application will fail to start with an exception.
>
> Is this true? Or should that be ...logging will fail to start with an
> exception.
>
> Sent from my iPhone
>
> > On 2014/09/22, at 8:09, mattsicker@apache.org wrote:
> >
> > Doc update regarding how servlet contexts can be named.
> >
> >
> > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> > Commit:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3c868456
> > Tree:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3c868456
> > Diff:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3c868456
> >
> > Branch: refs/heads/master
> > Commit: 3c868456ed043673a889cdcd0afe3513a695dd72
> > Parents: 0e5cc42
> > Author: Matt Sicker <ma...@apache.org>
> > Authored: Sun Sep 21 17:21:07 2014 -0500
> > Committer: Matt Sicker <ma...@apache.org>
> > Committed: Sun Sep 21 17:21:07 2014 -0500
> >
> > ----------------------------------------------------------------------
> > src/site/xdoc/manual/webapp.xml | 12 +++++++-----
> > 1 file changed, 7 insertions(+), 5 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> >
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c868456/src/site/xdoc/manual/webapp.xml
> > ----------------------------------------------------------------------
> > diff --git a/src/site/xdoc/manual/webapp.xml
> b/src/site/xdoc/manual/webapp.xml
> > index ecad1f9..1b86d45 100644
> > --- a/src/site/xdoc/manual/webapp.xml
> > +++ b/src/site/xdoc/manual/webapp.xml
> > @@ -177,17 +177,19 @@
> >       <subsection name="Context Parameters">
> >         <a name="ContextParams" />
> >         <p>
> > -          By default, Log4j 2 uses the <code>ServletContext</code>'s
> context name as the <code>LoggerContext</code> name
> > -          and uses the standard pattern for locating the Log4j
> configuration file. There are three context parameters
> > -          that you can use to control this behavior. The first,
> <code>isLog4jContextSelectorNamed</code>, specifies
> > -          whether the context should be selected using the
> > +          By default, Log4j 2 uses the <code>ServletContext</code>'s
> > +          <a href="
> http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getServletContextName()">context
> name</a>
> > +          as the <code>LoggerContext</code> name and uses the standard
> pattern for locating the Log4j configuration
> > +          file. There are three context parameters that you can use to
> control this behavior. The first,
> > +          <code>isLog4jContextSelectorNamed</code>, specifies whether
> the context should be selected using the
> >           <a class="javadoc"
> href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
> >> JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code> is
> not specified or is anything other
> >           than <code>true</code>, it is assumed to be <code>false</code>.
> >         </p>
> >         <p>
> >           If <code>isLog4jContextSelectorNamed</code> is
> <code>true</code>, <code>log4jContextName</code> must be
> > -          specified; otherwise, the application will fail to start with
> an exception. <code>log4jConfiguration</code>
> > +          specified or <code>display-name</code> must be specified in
> <code>web.xml</code>; otherwise, the application
> > +          will fail to start with an exception.
> <code>log4jConfiguration</code>
> >           <em>should</em> also be specified in this case, and must be a
> valid URI for the configuration file; however,
> >           this parameter is not required.
> >         </p>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>


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

Re: [2/4] git commit: Doc update regarding how servlet contexts can be named.

Posted by Remko Popma <re...@gmail.com>.
The docs say
> otherwise, the application will fail to start with an exception. 

Is this true? Or should that be ...logging will fail to start with an exception. 

Sent from my iPhone

> On 2014/09/22, at 8:09, mattsicker@apache.org wrote:
> 
> Doc update regarding how servlet contexts can be named.
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3c868456
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3c868456
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3c868456
> 
> Branch: refs/heads/master
> Commit: 3c868456ed043673a889cdcd0afe3513a695dd72
> Parents: 0e5cc42
> Author: Matt Sicker <ma...@apache.org>
> Authored: Sun Sep 21 17:21:07 2014 -0500
> Committer: Matt Sicker <ma...@apache.org>
> Committed: Sun Sep 21 17:21:07 2014 -0500
> 
> ----------------------------------------------------------------------
> src/site/xdoc/manual/webapp.xml | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c868456/src/site/xdoc/manual/webapp.xml
> ----------------------------------------------------------------------
> diff --git a/src/site/xdoc/manual/webapp.xml b/src/site/xdoc/manual/webapp.xml
> index ecad1f9..1b86d45 100644
> --- a/src/site/xdoc/manual/webapp.xml
> +++ b/src/site/xdoc/manual/webapp.xml
> @@ -177,17 +177,19 @@
>       <subsection name="Context Parameters">
>         <a name="ContextParams" />
>         <p>
> -          By default, Log4j 2 uses the <code>ServletContext</code>'s context name as the <code>LoggerContext</code> name
> -          and uses the standard pattern for locating the Log4j configuration file. There are three context parameters
> -          that you can use to control this behavior. The first, <code>isLog4jContextSelectorNamed</code>, specifies
> -          whether the context should be selected using the
> +          By default, Log4j 2 uses the <code>ServletContext</code>'s
> +          <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getServletContextName()">context name</a>
> +          as the <code>LoggerContext</code> name and uses the standard pattern for locating the Log4j configuration
> +          file. There are three context parameters that you can use to control this behavior. The first,
> +          <code>isLog4jContextSelectorNamed</code>, specifies whether the context should be selected using the
>           <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
>> JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code> is not specified or is anything other
>           than <code>true</code>, it is assumed to be <code>false</code>.
>         </p>
>         <p>
>           If <code>isLog4jContextSelectorNamed</code> is <code>true</code>, <code>log4jContextName</code> must be
> -          specified; otherwise, the application will fail to start with an exception. <code>log4jConfiguration</code>
> +          specified or <code>display-name</code> must be specified in <code>web.xml</code>; otherwise, the application
> +          will fail to start with an exception. <code>log4jConfiguration</code>
>           <em>should</em> also be specified in this case, and must be a valid URI for the configuration file; however,
>           this parameter is not required.
>         </p>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[2/4] git commit: Doc update regarding how servlet contexts can be named.

Posted by ma...@apache.org.
Doc update regarding how servlet contexts can be named.


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

Branch: refs/heads/master
Commit: 3c868456ed043673a889cdcd0afe3513a695dd72
Parents: 0e5cc42
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 17:21:07 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 17:21:07 2014 -0500

----------------------------------------------------------------------
 src/site/xdoc/manual/webapp.xml | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c868456/src/site/xdoc/manual/webapp.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/webapp.xml b/src/site/xdoc/manual/webapp.xml
index ecad1f9..1b86d45 100644
--- a/src/site/xdoc/manual/webapp.xml
+++ b/src/site/xdoc/manual/webapp.xml
@@ -177,17 +177,19 @@
       <subsection name="Context Parameters">
         <a name="ContextParams" />
         <p>
-          By default, Log4j 2 uses the <code>ServletContext</code>'s context name as the <code>LoggerContext</code> name
-          and uses the standard pattern for locating the Log4j configuration file. There are three context parameters
-          that you can use to control this behavior. The first, <code>isLog4jContextSelectorNamed</code>, specifies
-          whether the context should be selected using the
+          By default, Log4j 2 uses the <code>ServletContext</code>'s
+          <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getServletContextName()">context name</a>
+          as the <code>LoggerContext</code> name and uses the standard pattern for locating the Log4j configuration
+          file. There are three context parameters that you can use to control this behavior. The first,
+          <code>isLog4jContextSelectorNamed</code>, specifies whether the context should be selected using the
           <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
             >JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code> is not specified or is anything other
           than <code>true</code>, it is assumed to be <code>false</code>.
         </p>
         <p>
           If <code>isLog4jContextSelectorNamed</code> is <code>true</code>, <code>log4jContextName</code> must be
-          specified; otherwise, the application will fail to start with an exception. <code>log4jConfiguration</code>
+          specified or <code>display-name</code> must be specified in <code>web.xml</code>; otherwise, the application
+          will fail to start with an exception. <code>log4jConfiguration</code>
           <em>should</em> also be specified in this case, and must be a valid URI for the configuration file; however,
           this parameter is not required.
         </p>


[4/4] git commit: Update ConfigurationFactory.Factory to use TCCL.

Posted by ma...@apache.org.
Update ConfigurationFactory.Factory to use TCCL.

  - Prefer use of LoaderUtil.
  - Should help fix issues involving the Log4j ClassLoader and the
  application's ClassLoader being different (e.g., LOG4J2-795).


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

Branch: refs/heads/master
Commit: cb631914cef1cd27a2bba38bb13977f02a1bb5be
Parents: 2fb7d67
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 18:04:18 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 18:04:18 2014 -0500

----------------------------------------------------------------------
 .../logging/log4j/core/config/ConfigurationFactory.java | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cb631914/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
index 37e3f80..e9c0d7b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
@@ -42,7 +42,9 @@ import org.apache.logging.log4j.core.lookup.Interpolator;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.core.util.FileUtils;
 import org.apache.logging.log4j.core.util.Loader;
+import org.apache.logging.log4j.core.util.ReflectionUtil;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.LoaderUtil;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
@@ -163,7 +165,7 @@ public abstract class ConfigurationFactory {
     @SuppressWarnings("unchecked")
     private static void addFactory(final Collection<ConfigurationFactory> list, final String factoryClass) {
         try {
-            addFactory(list, (Class<ConfigurationFactory>) Loader.loadClass(factoryClass));
+            addFactory(list, (Class<ConfigurationFactory>) LoaderUtil.loadClass(factoryClass));
         } catch (final Exception ex) {
             LOGGER.error("Unable to load class {}", factoryClass, ex);
         }
@@ -172,7 +174,7 @@ public abstract class ConfigurationFactory {
     private static void addFactory(final Collection<ConfigurationFactory> list,
                                    final Class<ConfigurationFactory> factoryClass) {
         try {
-            list.add(factoryClass.getConstructor().newInstance());
+            list.add(ReflectionUtil.instantiate(factoryClass));
         } catch (final Exception ex) {
             LOGGER.error("Unable to create instance of {}", factoryClass.getName(), ex);
         }
@@ -249,7 +251,7 @@ public abstract class ConfigurationFactory {
         final boolean isClassLoaderScheme = scheme != null && scheme.equals(CLASS_LOADER_SCHEME);
         final boolean isClassPathScheme = scheme != null && !isClassLoaderScheme && scheme.equals(CLASS_PATH_SCHEME);
         if (scheme == null || isClassLoaderScheme || isClassPathScheme) {
-            final ClassLoader loader = Loader.getThreadContextClassLoader();
+            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
             String path;
             if (isClassLoaderScheme || isClassPathScheme) {
                 path = configLocation.getSchemeSpecificPart();
@@ -389,7 +391,7 @@ public abstract class ConfigurationFactory {
                         LOGGER.catching(Level.DEBUG, ex);
                     }
                     if (source == null) {
-                        final ClassLoader loader = this.getClass().getClassLoader();
+                        final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
                         source = getInputFromString(config, loader);
                     }
                     if (source != null) {
@@ -443,7 +445,7 @@ public abstract class ConfigurationFactory {
 
         private Configuration getConfiguration(final boolean isTest, final String name) {
             final boolean named = name != null && name.length() > 0;
-            final ClassLoader loader = this.getClass().getClassLoader();
+            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
             for (final ConfigurationFactory factory : factories) {
                 String configName;
                 final String prefix = isTest ? TEST_PREFIX : DEFAULT_PREFIX;


[3/4] git commit: Upgrade log call to fatal.

Posted by ma...@apache.org.
Upgrade log call to fatal.


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

Branch: refs/heads/master
Commit: 2fb7d67dd269c3fa84efad89e44bd041c4782c1d
Parents: 3c86845
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 17:26:11 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 17:26:11 2014 -0500

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/config/Configurator.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2fb7d67d/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
index 78ab067..71c9d55 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
@@ -159,7 +159,7 @@ public final class Configurator {
                     factory.getClass().getName(), Log4jContextFactory.class.getName());
             return null;
         } else {
-            LOGGER.error("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!");
+            LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!");
             return null;
         }
     }