You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2021/02/24 14:20:36 UTC

[log4j][log4j-web] Start and Stop Order?

Hi All:

I have a bug in a web app where I use log4j-web:
- Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app, which is correct.
- The App runs and uses Log4j 2
- When I stop or undeploy the web app, Tomcat complains about a Log4j
thread still hanging around because:
- Tomcat stops Log4j FIRST (which is wrong for this stack).
- Tomcat stops the web-app which cause some logging
- Log4j re-initializes itself

So... Can we fix this in our web fragment? Can we say "start first and
stop last"?

Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10) help?

TY!
Gary

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


Re: [log4j][log4j-web] Start and Stop Order?

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Feb 24, 2021 at 11:07 AM Ralph Goers <ra...@dslextreme.com> wrote:
>
> Interesting that you posted this to the user list.

I'm a real user in this case :-)

>
> Last I checked the way the shutdown worked was very much dependent on which servlet spec version the app is using. As I recall, prior to 3.0 a servlet filter had to be directly configured by the user. Configuring that in the web.xml as the first filter pretty much guaranteed proper ordering. With 3.0 I believe a ServletContainerInitializer is used instead to register the filter. I believe the ordering of that is only guaranteed if Log4j’s ServletContainerInitializer is called before any others.

I'm using Tomcat 9 just because that is the use case of our QA today
and I'm happy to use Tomcat 10 instead.

I am trying to find a way to get our web fragment to behave which is
really a dev-ML topic ;-)

I will try to hardwire Log4j shutdown from our own servlets...

Gary

>
> Ralph
>
> > On Feb 24, 2021, at 7:20 AM, Gary Gregory <ga...@gmail.com> wrote:
> >
> > Hi All:
> >
> > I have a bug in a web app where I use log4j-web:
> > - Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app, which is correct.
> > - The App runs and uses Log4j 2
> > - When I stop or undeploy the web app, Tomcat complains about a Log4j
> > thread still hanging around because:
> > - Tomcat stops Log4j FIRST (which is wrong for this stack).
> > - Tomcat stops the web-app which cause some logging
> > - Log4j re-initializes itself
> >
> > So... Can we fix this in our web fragment? Can we say "start first and
> > stop last"?
> >
> > Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10) help?
> >
> > TY!
> > Gary
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Re: [log4j][log4j-web] Start and Stop Order?

Posted by Ralph Goers <ra...@dslextreme.com>.
I’m first on start should always imply I am last on stop.

I am not aware of the web fragment support that was added.

Ralph

> On Feb 24, 2021, at 9:44 AM, Gary Gregory <ga...@gmail.com> wrote:
> 
> On Wed, Feb 24, 2021 at 11:37 AM Matt Sicker <bo...@gmail.com> wrote:
>> 
>> This behavior was recently changed but not released yet.
> 
> It has though:
> 
> 2.14.0's log4j-web contains a web fragment xml configuration file that
> says "I'm first". The problem is that I need (as does everyone I
> claim) "I'm first" on start and "I'm last" on stop.
> 
> Or am I missing something?
> 
> Gary
> 
>> 
>> On Wed, 24 Feb 2021 at 10:07, Ralph Goers <ra...@dslextreme.com> wrote:
>>> 
>>> Interesting that you posted this to the user list.
>>> 
>>> Last I checked the way the shutdown worked was very much dependent on which servlet spec version the app is using. As I recall, prior to 3.0 a servlet filter had to be directly configured by the user. Configuring that in the web.xml as the first filter pretty much guaranteed proper ordering. With 3.0 I believe a ServletContainerInitializer is used instead to register the filter. I believe the ordering of that is only guaranteed if Log4j’s ServletContainerInitializer is called before any others.
>>> 
>>> Ralph
>>> 
>>>> On Feb 24, 2021, at 7:20 AM, Gary Gregory <ga...@gmail.com> wrote:
>>>> 
>>>> Hi All:
>>>> 
>>>> I have a bug in a web app where I use log4j-web:
>>>> - Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app, which is correct.
>>>> - The App runs and uses Log4j 2
>>>> - When I stop or undeploy the web app, Tomcat complains about a Log4j
>>>> thread still hanging around because:
>>>> - Tomcat stops Log4j FIRST (which is wrong for this stack).
>>>> - Tomcat stops the web-app which cause some logging
>>>> - Log4j re-initializes itself
>>>> 
>>>> So... Can we fix this in our web fragment? Can we say "start first and
>>>> stop last"?
>>>> 
>>>> Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10) help?
>>>> 
>>>> TY!
>>>> Gary
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>> 
>>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



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


Re: [log4j][log4j-web] Start and Stop Order?

Posted by Gary Gregory <ga...@gmail.com>.
I think that PR is not helpful for my use case.

Also in general, I push back PR like this one because it adds a whole new
class with ZERO Javadoc: Log4jShutdownOnContextDestroyedListener

Gary

On Wed, Feb 24, 2021, 11:47 Matt Sicker <bo...@gmail.com> wrote:

> https://github.com/apache/logging-log4j2/pull/463 added more to this
> feature. Might help fix your problem.
>
> On Wed, 24 Feb 2021 at 10:44, Gary Gregory <ga...@gmail.com> wrote:
> >
> > On Wed, Feb 24, 2021 at 11:37 AM Matt Sicker <bo...@gmail.com> wrote:
> > >
> > > This behavior was recently changed but not released yet.
> >
> > It has though:
> >
> > 2.14.0's log4j-web contains a web fragment xml configuration file that
> > says "I'm first". The problem is that I need (as does everyone I
> > claim) "I'm first" on start and "I'm last" on stop.
> >
> > Or am I missing something?
> >
> > Gary
> >
> > >
> > > On Wed, 24 Feb 2021 at 10:07, Ralph Goers <ra...@dslextreme.com>
> wrote:
> > > >
> > > > Interesting that you posted this to the user list.
> > > >
> > > > Last I checked the way the shutdown worked was very much dependent
> on which servlet spec version the app is using. As I recall, prior to 3.0 a
> servlet filter had to be directly configured by the user. Configuring that
> in the web.xml as the first filter pretty much guaranteed proper ordering.
> With 3.0 I believe a ServletContainerInitializer is used instead to
> register the filter. I believe the ordering of that is only guaranteed if
> Log4j’s ServletContainerInitializer is called before any others.
> > > >
> > > > Ralph
> > > >
> > > > > On Feb 24, 2021, at 7:20 AM, Gary Gregory <ga...@gmail.com>
> wrote:
> > > > >
> > > > > Hi All:
> > > > >
> > > > > I have a bug in a web app where I use log4j-web:
> > > > > - Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app,
> which is correct.
> > > > > - The App runs and uses Log4j 2
> > > > > - When I stop or undeploy the web app, Tomcat complains about a
> Log4j
> > > > > thread still hanging around because:
> > > > > - Tomcat stops Log4j FIRST (which is wrong for this stack).
> > > > > - Tomcat stops the web-app which cause some logging
> > > > > - Log4j re-initializes itself
> > > > >
> > > > > So... Can we fix this in our web fragment? Can we say "start first
> and
> > > > > stop last"?
> > > > >
> > > > > Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10)
> help?
> > > > >
> > > > > TY!
> > > > > Gary
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > > > For additional commands, e-mail:
> log4j-user-help@logging.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: [log4j][log4j-web] Start and Stop Order?

Posted by Matt Sicker <bo...@gmail.com>.
https://github.com/apache/logging-log4j2/pull/463 added more to this
feature. Might help fix your problem.

On Wed, 24 Feb 2021 at 10:44, Gary Gregory <ga...@gmail.com> wrote:
>
> On Wed, Feb 24, 2021 at 11:37 AM Matt Sicker <bo...@gmail.com> wrote:
> >
> > This behavior was recently changed but not released yet.
>
> It has though:
>
> 2.14.0's log4j-web contains a web fragment xml configuration file that
> says "I'm first". The problem is that I need (as does everyone I
> claim) "I'm first" on start and "I'm last" on stop.
>
> Or am I missing something?
>
> Gary
>
> >
> > On Wed, 24 Feb 2021 at 10:07, Ralph Goers <ra...@dslextreme.com> wrote:
> > >
> > > Interesting that you posted this to the user list.
> > >
> > > Last I checked the way the shutdown worked was very much dependent on which servlet spec version the app is using. As I recall, prior to 3.0 a servlet filter had to be directly configured by the user. Configuring that in the web.xml as the first filter pretty much guaranteed proper ordering. With 3.0 I believe a ServletContainerInitializer is used instead to register the filter. I believe the ordering of that is only guaranteed if Log4j’s ServletContainerInitializer is called before any others.
> > >
> > > Ralph
> > >
> > > > On Feb 24, 2021, at 7:20 AM, Gary Gregory <ga...@gmail.com> wrote:
> > > >
> > > > Hi All:
> > > >
> > > > I have a bug in a web app where I use log4j-web:
> > > > - Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app, which is correct.
> > > > - The App runs and uses Log4j 2
> > > > - When I stop or undeploy the web app, Tomcat complains about a Log4j
> > > > thread still hanging around because:
> > > > - Tomcat stops Log4j FIRST (which is wrong for this stack).
> > > > - Tomcat stops the web-app which cause some logging
> > > > - Log4j re-initializes itself
> > > >
> > > > So... Can we fix this in our web fragment? Can we say "start first and
> > > > stop last"?
> > > >
> > > > Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10) help?
> > > >
> > > > TY!
> > > > Gary
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > > >
> > > >
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Re: [log4j][log4j-web] Start and Stop Order?

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Feb 24, 2021 at 11:37 AM Matt Sicker <bo...@gmail.com> wrote:
>
> This behavior was recently changed but not released yet.

It has though:

2.14.0's log4j-web contains a web fragment xml configuration file that
says "I'm first". The problem is that I need (as does everyone I
claim) "I'm first" on start and "I'm last" on stop.

Or am I missing something?

Gary

>
> On Wed, 24 Feb 2021 at 10:07, Ralph Goers <ra...@dslextreme.com> wrote:
> >
> > Interesting that you posted this to the user list.
> >
> > Last I checked the way the shutdown worked was very much dependent on which servlet spec version the app is using. As I recall, prior to 3.0 a servlet filter had to be directly configured by the user. Configuring that in the web.xml as the first filter pretty much guaranteed proper ordering. With 3.0 I believe a ServletContainerInitializer is used instead to register the filter. I believe the ordering of that is only guaranteed if Log4j’s ServletContainerInitializer is called before any others.
> >
> > Ralph
> >
> > > On Feb 24, 2021, at 7:20 AM, Gary Gregory <ga...@gmail.com> wrote:
> > >
> > > Hi All:
> > >
> > > I have a bug in a web app where I use log4j-web:
> > > - Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app, which is correct.
> > > - The App runs and uses Log4j 2
> > > - When I stop or undeploy the web app, Tomcat complains about a Log4j
> > > thread still hanging around because:
> > > - Tomcat stops Log4j FIRST (which is wrong for this stack).
> > > - Tomcat stops the web-app which cause some logging
> > > - Log4j re-initializes itself
> > >
> > > So... Can we fix this in our web fragment? Can we say "start first and
> > > stop last"?
> > >
> > > Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10) help?
> > >
> > > TY!
> > > Gary
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > >
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Re: [log4j][log4j-web] Start and Stop Order?

Posted by Matt Sicker <bo...@gmail.com>.
This behavior was recently changed but not released yet.

On Wed, 24 Feb 2021 at 10:07, Ralph Goers <ra...@dslextreme.com> wrote:
>
> Interesting that you posted this to the user list.
>
> Last I checked the way the shutdown worked was very much dependent on which servlet spec version the app is using. As I recall, prior to 3.0 a servlet filter had to be directly configured by the user. Configuring that in the web.xml as the first filter pretty much guaranteed proper ordering. With 3.0 I believe a ServletContainerInitializer is used instead to register the filter. I believe the ordering of that is only guaranteed if Log4j’s ServletContainerInitializer is called before any others.
>
> Ralph
>
> > On Feb 24, 2021, at 7:20 AM, Gary Gregory <ga...@gmail.com> wrote:
> >
> > Hi All:
> >
> > I have a bug in a web app where I use log4j-web:
> > - Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app, which is correct.
> > - The App runs and uses Log4j 2
> > - When I stop or undeploy the web app, Tomcat complains about a Log4j
> > thread still hanging around because:
> > - Tomcat stops Log4j FIRST (which is wrong for this stack).
> > - Tomcat stops the web-app which cause some logging
> > - Log4j re-initializes itself
> >
> > So... Can we fix this in our web fragment? Can we say "start first and
> > stop last"?
> >
> > Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10) help?
> >
> > TY!
> > Gary
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Re: [log4j][log4j-web] Start and Stop Order?

Posted by Ralph Goers <ra...@dslextreme.com>.
Interesting that you posted this to the user list.

Last I checked the way the shutdown worked was very much dependent on which servlet spec version the app is using. As I recall, prior to 3.0 a servlet filter had to be directly configured by the user. Configuring that in the web.xml as the first filter pretty much guaranteed proper ordering. With 3.0 I believe a ServletContainerInitializer is used instead to register the filter. I believe the ordering of that is only guaranteed if Log4j’s ServletContainerInitializer is called before any others. 

Ralph

> On Feb 24, 2021, at 7:20 AM, Gary Gregory <ga...@gmail.com> wrote:
> 
> Hi All:
> 
> I have a bug in a web app where I use log4j-web:
> - Tomcat 9 correctly starts Log4j 2 FIRST, BEFORE the web-app, which is correct.
> - The App runs and uses Log4j 2
> - When I stop or undeploy the web app, Tomcat complains about a Log4j
> thread still hanging around because:
> - Tomcat stops Log4j FIRST (which is wrong for this stack).
> - Tomcat stops the web-app which cause some logging
> - Log4j re-initializes itself
> 
> So... Can we fix this in our web fragment? Can we say "start first and
> stop last"?
> 
> Can I say that at all in server.xml? Does Servlet 5.0 (Tomcat 10) help?
> 
> TY!
> Gary
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



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