How to change the log4j2 log level of a running application without restarting?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to change the log4j2 log level of a running application without restarting?

alwin james
Hi Team,

How can we change the log level of a running application without
restarting the program?

It will be really helpful if someone can point me in the right direction.

Any Java examples or documentation?

I used to achieve this using 'DOMConfigurator' in log4j.

Regards,
Reply | Threaded
Open this post in threaded view
|

Re: How to change the log4j2 log level of a running application without restarting?

Gary Gregory-4
HiHi,

Take a look at the Configurator class.

Gary

On Tue, Apr 2, 2019, 19:19 alwin james <[hidden email]> wrote:

> Hi Team,
>
> How can we change the log level of a running application without
> restarting the program?
>
> It will be really helpful if someone can point me in the right direction.
>
> Any Java examples or documentation?
>
> I used to achieve this using 'DOMConfigurator' in log4j.
>
> Regards,
>
Reply | Threaded
Open this post in threaded view
|

Re: How to change the log4j2 log level of a running application without restarting?

Ralph Goers
In reply to this post by alwin james
There are several ways. If you are using Spring Boot you can use the REST API they provide. If you are using a configuration file just add monitorInterval=n where n is the number of seconds to poll for changes. The configuration will automatically reload if you do that. Finally, as Gary noted you can programmatically do that using the Configurator class.

Ralph

> On Apr 2, 2019, at 4:10 PM, alwin james <[hidden email]> wrote:
>
> Hi Team,
>
> How can we change the log level of a running application without
> restarting the program?
>
> It will be really helpful if someone can point me in the right direction.
>
> Any Java examples or documentation?
>
> I used to achieve this using 'DOMConfigurator' in log4j.
>
> Regards,



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to change the log4j2 log level of a running application without restarting?

Alex O'Ree
Isn't there a JMX/mbean based solution?

On Tue, Apr 2, 2019 at 8:29 PM Ralph Goers <[hidden email]>
wrote:

> There are several ways. If you are using Spring Boot you can use the REST
> API they provide. If you are using a configuration file just add
> monitorInterval=n where n is the number of seconds to poll for changes. The
> configuration will automatically reload if you do that. Finally, as Gary
> noted you can programmatically do that using the Configurator class.
>
> Ralph
>
> > On Apr 2, 2019, at 4:10 PM, alwin james <[hidden email]> wrote:
> >
> > Hi Team,
> >
> > How can we change the log level of a running application without
> > restarting the program?
> >
> > It will be really helpful if someone can point me in the right direction.
> >
> > Any Java examples or documentation?
> >
> > I used to achieve this using 'DOMConfigurator' in log4j.
> >
> > Regards,
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to change the log4j2 log level of a running application without restarting?

alwin james
In reply to this post by Ralph Goers
Thank you Ralph and Gary for quick response.

I was testing using the 'monitorInterval' in intellij. I was testing by
changing log4j2.xml file in 'resources' folder.
I completely forgot the fact that the files get copied to 'out' from the
source folder when intellij starts running the application.

Regards,
Alwin

On Tue, Apr 2, 2019, 5:29 PM Ralph Goers <[hidden email]> wrote:

> There are several ways. If you are using Spring Boot you can use the REST
> API they provide. If you are using a configuration file just add
> monitorInterval=n where n is the number of seconds to poll for changes. The
> configuration will automatically reload if you do that. Finally, as Gary
> noted you can programmatically do that using the Configurator class.
>
> Ralph
>
> > On Apr 2, 2019, at 4:10 PM, alwin james <[hidden email]> wrote:
> >
> > Hi Team,
> >
> > How can we change the log level of a running application without
> > restarting the program?
> >
> > It will be really helpful if someone can point me in the right direction.
> >
> > Any Java examples or documentation?
> >
> > I used to achieve this using 'DOMConfigurator' in log4j.
> >
> > Regards,
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to change the log4j2 log level of a running application without restarting?

Remko Popma-2
In reply to this post by Alex O'Ree


> On Apr 3, 2019, at 9:34, Alex O'Ree <[hidden email]> wrote:
>
> Isn't there a JMX/mbean based solution?
Yes there is.
This page has more detail: https://logging.apache.org/log4j/2.x/manual/jmx.html

I remember there is an MBean API for changing the log level.


>
> On Tue, Apr 2, 2019 at 8:29 PM Ralph Goers <[hidden email]>
> wrote:
>
>> There are several ways. If you are using Spring Boot you can use the REST
>> API they provide. If you are using a configuration file just add
>> monitorInterval=n where n is the number of seconds to poll for changes. The
>> configuration will automatically reload if you do that. Finally, as Gary
>> noted you can programmatically do that using the Configurator class.
>>
>> Ralph
>>
>>> On Apr 2, 2019, at 4:10 PM, alwin james <[hidden email]> wrote:
>>>
>>> Hi Team,
>>>
>>> How can we change the log level of a running application without
>>> restarting the program?
>>>
>>> It will be really helpful if someone can point me in the right direction.
>>>
>>> Any Java examples or documentation?
>>>
>>> I used to achieve this using 'DOMConfigurator' in log4j.
>>>
>>> Regards,
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>