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 kriegerd <kr...@gmail.com> on 2017/03/15 01:53:39 UTC

LogManager.resetConfiguration in log4j2

Hi,

Is there a way to emulate the behavior of LogManager.resetConfiguration in
log4j2?

We need to migrate the functionality of an older class that uses it.
Thanks!

Alejandro.

Re: LogManager.resetConfiguration in log4j2

Posted by kriegerd <kr...@gmail.com>.
Thanks a lot for the help.
I'll try it today.

Alejandro.

On Tue, Mar 14, 2017 at 10:34 PM Ralph Goers <ra...@dslextreme.com>
wrote:

> Actually, the equivalent would be set the configuration back to the
> DefaultConfiguratoin, not a null configuration.
>
> Ralph
>
> > On Mar 14, 2017, at 9:09 PM, Matt Sicker <bo...@gmail.com> wrote:
> >
> > After looking at the source code for Hierarchy::resetConfiguration(), I
> see
> > that there's no specific analog in 2.x. However, the following snippet
> > should do about the same thing:
> >
> > LoggerContext ctx = LoggerContext.getContext(false);
> > ctx.setConfiguration(new NullConfiguration());
> >
> >
> > On 14 March 2017 at 22:28, Matt Sicker <bo...@gmail.com> wrote:
> >
> >> I'm not exactly sure what that's supposed to do, but if you cast the
> >> LoggerContext from LogManager.getContext() to the implementation class
> in
> >> log4j-core, there's a reconfigure() method.
> >>
> >> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/
> >> org/apache/logging/log4j/core/LoggerContext.html
> >>
> >> On 14 March 2017 at 20:53, kriegerd <kr...@gmail.com> wrote:
> >>
> >>> Hi,
> >>>
> >>> Is there a way to emulate the behavior of
> LogManager.resetConfiguration in
> >>> log4j2?
> >>>
> >>> We need to migrate the functionality of an older class that uses it.
> >>> Thanks!
> >>>
> >>> Alejandro.
> >>>
> >>
> >>
> >>
> >> --
> >> Matt Sicker <bo...@gmail.com>
> >>
> >
> >
> >
> > --
> > Matt Sicker <bo...@gmail.com>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: LogManager.resetConfiguration in log4j2

Posted by Ralph Goers <ra...@dslextreme.com>.
Just use Configurator.initialize(new DefaultConfiguration());

Ralph

> On Mar 15, 2017, at 9:09 AM, kriegerd <kr...@gmail.com> wrote:
> 
> I'm seeing that LoggerContext.setConfiguration is private and is being used
> by start(Configuration) or onChange(Reconfigurable).
> 
> Would using start work? I check the start method, and it seems it's ok to
> use, but just wondering if anyone had any info about it.
> 
> Thanks again.
> 
> Alejandro.
> 
> On Wed, Mar 15, 2017 at 7:49 AM Matt Sicker <bo...@gmail.com> wrote:
> 
>> Looking at the source code for resetConfiguration, it says it clears out
>> all appenders and levels and whatnot. I suppose depending on the goals,
>> yes, DefaultConfiguration makes more sense usually unless you're trying to
>> disable logging while you manually configure things in some strange way.
>> 
>> On 15 March 2017 at 00:34, Ralph Goers <ra...@dslextreme.com> wrote:
>> 
>>> Actually, the equivalent would be set the configuration back to the
>>> DefaultConfiguratoin, not a null configuration.
>>> 
>>> Ralph
>>> 
>>>> On Mar 14, 2017, at 9:09 PM, Matt Sicker <bo...@gmail.com> wrote:
>>>> 
>>>> After looking at the source code for Hierarchy::resetConfiguration(), I
>>> see
>>>> that there's no specific analog in 2.x. However, the following snippet
>>>> should do about the same thing:
>>>> 
>>>> LoggerContext ctx = LoggerContext.getContext(false);
>>>> ctx.setConfiguration(new NullConfiguration());
>>>> 
>>>> 
>>>> On 14 March 2017 at 22:28, Matt Sicker <bo...@gmail.com> wrote:
>>>> 
>>>>> I'm not exactly sure what that's supposed to do, but if you cast the
>>>>> LoggerContext from LogManager.getContext() to the implementation class
>>> in
>>>>> log4j-core, there's a reconfigure() method.
>>>>> 
>>>>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/
>>>>> org/apache/logging/log4j/core/LoggerContext.html
>>>>> 
>>>>> On 14 March 2017 at 20:53, kriegerd <kr...@gmail.com> wrote:
>>>>> 
>>>>>> Hi,
>>>>>> 
>>>>>> Is there a way to emulate the behavior of
>>> LogManager.resetConfiguration in
>>>>>> log4j2?
>>>>>> 
>>>>>> We need to migrate the functionality of an older class that uses it.
>>>>>> Thanks!
>>>>>> 
>>>>>> Alejandro.
>>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> Matt Sicker <bo...@gmail.com>
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>> 
>>> 
>> 
>> 
>> --
>> Matt Sicker <bo...@gmail.com>
>> 



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


Re: LogManager.resetConfiguration in log4j2

Posted by kriegerd <kr...@gmail.com>.
I'm seeing that LoggerContext.setConfiguration is private and is being used
by start(Configuration) or onChange(Reconfigurable).

Would using start work? I check the start method, and it seems it's ok to
use, but just wondering if anyone had any info about it.

Thanks again.

Alejandro.

On Wed, Mar 15, 2017 at 7:49 AM Matt Sicker <bo...@gmail.com> wrote:

> Looking at the source code for resetConfiguration, it says it clears out
> all appenders and levels and whatnot. I suppose depending on the goals,
> yes, DefaultConfiguration makes more sense usually unless you're trying to
> disable logging while you manually configure things in some strange way.
>
> On 15 March 2017 at 00:34, Ralph Goers <ra...@dslextreme.com> wrote:
>
> > Actually, the equivalent would be set the configuration back to the
> > DefaultConfiguratoin, not a null configuration.
> >
> > Ralph
> >
> > > On Mar 14, 2017, at 9:09 PM, Matt Sicker <bo...@gmail.com> wrote:
> > >
> > > After looking at the source code for Hierarchy::resetConfiguration(), I
> > see
> > > that there's no specific analog in 2.x. However, the following snippet
> > > should do about the same thing:
> > >
> > > LoggerContext ctx = LoggerContext.getContext(false);
> > > ctx.setConfiguration(new NullConfiguration());
> > >
> > >
> > > On 14 March 2017 at 22:28, Matt Sicker <bo...@gmail.com> wrote:
> > >
> > >> I'm not exactly sure what that's supposed to do, but if you cast the
> > >> LoggerContext from LogManager.getContext() to the implementation class
> > in
> > >> log4j-core, there's a reconfigure() method.
> > >>
> > >> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/
> > >> org/apache/logging/log4j/core/LoggerContext.html
> > >>
> > >> On 14 March 2017 at 20:53, kriegerd <kr...@gmail.com> wrote:
> > >>
> > >>> Hi,
> > >>>
> > >>> Is there a way to emulate the behavior of
> > LogManager.resetConfiguration in
> > >>> log4j2?
> > >>>
> > >>> We need to migrate the functionality of an older class that uses it.
> > >>> Thanks!
> > >>>
> > >>> Alejandro.
> > >>>
> > >>
> > >>
> > >>
> > >> --
> > >> Matt Sicker <bo...@gmail.com>
> > >>
> > >
> > >
> > >
> > > --
> > > Matt Sicker <bo...@gmail.com>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: LogManager.resetConfiguration in log4j2

Posted by Matt Sicker <bo...@gmail.com>.
Looking at the source code for resetConfiguration, it says it clears out
all appenders and levels and whatnot. I suppose depending on the goals,
yes, DefaultConfiguration makes more sense usually unless you're trying to
disable logging while you manually configure things in some strange way.

On 15 March 2017 at 00:34, Ralph Goers <ra...@dslextreme.com> wrote:

> Actually, the equivalent would be set the configuration back to the
> DefaultConfiguratoin, not a null configuration.
>
> Ralph
>
> > On Mar 14, 2017, at 9:09 PM, Matt Sicker <bo...@gmail.com> wrote:
> >
> > After looking at the source code for Hierarchy::resetConfiguration(), I
> see
> > that there's no specific analog in 2.x. However, the following snippet
> > should do about the same thing:
> >
> > LoggerContext ctx = LoggerContext.getContext(false);
> > ctx.setConfiguration(new NullConfiguration());
> >
> >
> > On 14 March 2017 at 22:28, Matt Sicker <bo...@gmail.com> wrote:
> >
> >> I'm not exactly sure what that's supposed to do, but if you cast the
> >> LoggerContext from LogManager.getContext() to the implementation class
> in
> >> log4j-core, there's a reconfigure() method.
> >>
> >> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/
> >> org/apache/logging/log4j/core/LoggerContext.html
> >>
> >> On 14 March 2017 at 20:53, kriegerd <kr...@gmail.com> wrote:
> >>
> >>> Hi,
> >>>
> >>> Is there a way to emulate the behavior of
> LogManager.resetConfiguration in
> >>> log4j2?
> >>>
> >>> We need to migrate the functionality of an older class that uses it.
> >>> Thanks!
> >>>
> >>> Alejandro.
> >>>
> >>
> >>
> >>
> >> --
> >> Matt Sicker <bo...@gmail.com>
> >>
> >
> >
> >
> > --
> > Matt Sicker <bo...@gmail.com>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


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

Re: LogManager.resetConfiguration in log4j2

Posted by Ralph Goers <ra...@dslextreme.com>.
Actually, the equivalent would be set the configuration back to the DefaultConfiguratoin, not a null configuration.

Ralph

> On Mar 14, 2017, at 9:09 PM, Matt Sicker <bo...@gmail.com> wrote:
> 
> After looking at the source code for Hierarchy::resetConfiguration(), I see
> that there's no specific analog in 2.x. However, the following snippet
> should do about the same thing:
> 
> LoggerContext ctx = LoggerContext.getContext(false);
> ctx.setConfiguration(new NullConfiguration());
> 
> 
> On 14 March 2017 at 22:28, Matt Sicker <bo...@gmail.com> wrote:
> 
>> I'm not exactly sure what that's supposed to do, but if you cast the
>> LoggerContext from LogManager.getContext() to the implementation class in
>> log4j-core, there's a reconfigure() method.
>> 
>> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/
>> org/apache/logging/log4j/core/LoggerContext.html
>> 
>> On 14 March 2017 at 20:53, kriegerd <kr...@gmail.com> wrote:
>> 
>>> Hi,
>>> 
>>> Is there a way to emulate the behavior of LogManager.resetConfiguration in
>>> log4j2?
>>> 
>>> We need to migrate the functionality of an older class that uses it.
>>> Thanks!
>>> 
>>> Alejandro.
>>> 
>> 
>> 
>> 
>> --
>> Matt Sicker <bo...@gmail.com>
>> 
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>



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


Re: LogManager.resetConfiguration in log4j2

Posted by Matt Sicker <bo...@gmail.com>.
After looking at the source code for Hierarchy::resetConfiguration(), I see
that there's no specific analog in 2.x. However, the following snippet
should do about the same thing:

LoggerContext ctx = LoggerContext.getContext(false);
ctx.setConfiguration(new NullConfiguration());


On 14 March 2017 at 22:28, Matt Sicker <bo...@gmail.com> wrote:

> I'm not exactly sure what that's supposed to do, but if you cast the
> LoggerContext from LogManager.getContext() to the implementation class in
> log4j-core, there's a reconfigure() method.
>
> https://logging.apache.org/log4j/2.x/log4j-core/apidocs/
> org/apache/logging/log4j/core/LoggerContext.html
>
> On 14 March 2017 at 20:53, kriegerd <kr...@gmail.com> wrote:
>
>> Hi,
>>
>> Is there a way to emulate the behavior of LogManager.resetConfiguration in
>> log4j2?
>>
>> We need to migrate the functionality of an older class that uses it.
>> Thanks!
>>
>> Alejandro.
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



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

Re: LogManager.resetConfiguration in log4j2

Posted by Matt Sicker <bo...@gmail.com>.
I'm not exactly sure what that's supposed to do, but if you cast the
LoggerContext from LogManager.getContext() to the implementation class in
log4j-core, there's a reconfigure() method.

https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/LoggerContext.html

On 14 March 2017 at 20:53, kriegerd <kr...@gmail.com> wrote:

> Hi,
>
> Is there a way to emulate the behavior of LogManager.resetConfiguration in
> log4j2?
>
> We need to migrate the functionality of an older class that uses it.
> Thanks!
>
> Alejandro.
>



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