loggerConfig.getAppenderRefs().clear()

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

loggerConfig.getAppenderRefs().clear()

EDMONDO SENA

Why this instruction goes in UnsupportedOperationException?

List<AppenderRef> value = loggerConfig.getAppenderRefs();
value.clear();

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Doug Wegscheid
 you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?

    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
 
 
Why this instruction goes in UnsupportedOperationException?

List<AppenderRef> value = loggerConfig.getAppenderRefs();
value.clear();

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

 
Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

EDMONDO SENA

Can you explain me how can i do it?

Regards.




On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:

>  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
>
>     On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
>  
>  
> Why this instruction goes in UnsupportedOperationException?
>
> List<AppenderRef> value = loggerConfig.getAppenderRefs();
> value.clear();
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Doug Wegscheid
 upon examination, I see that clearAppenders() is not public, so that won't work.
There is probably a way to do what you want, if you can tell us why you need to clear the appenders.

    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
 
 
Can you explain me how can i do it?

Regards.




On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:

>  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
>
>    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote: 


> Why this instruction goes in UnsupportedOperationException?
>
> List<AppenderRef> value = loggerConfig.getAppenderRefs();
> value.clear();
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

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

 
Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

EDMONDO SENA
In order to disable local logging when the external logging is enabled.
So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.


On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:

>  upon examination, I see that clearAppenders() is not public, so that won't work.
> There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
>
>     On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
>  
>  
> Can you explain me how can i do it?
>
> Regards.
>
>
>
>
> On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> >
> >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote: 
> > 
> > 
> > Why this instruction goes in UnsupportedOperationException?
> >
> > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > value.clear();
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> > 
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

EDMONDO SENA
Can you explain me this behaviour?

Map<String, Appender> appenders = config.getAppenders();
appenders.clear();        *** WORKING ***

Map<String, LoggerConfig> loggers = config.getLoggers();
loggers.clear();            *** GOES IN EXCEPTION DOESN'T WORK!!


On 2020/03/25 14:41:30, EDMONDO SENA <[hidden email]> wrote:

> In order to disable local logging when the external logging is enabled.
> So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
>
>
> On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> >
> >     On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
> >  
> >  
> > Can you explain me how can i do it?
> >
> > Regards.
> >
> >
> >
> >
> > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > >
> > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote: 
> > > 
> > > 
> > > Why this instruction goes in UnsupportedOperationException?
> > >
> > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > value.clear();
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > > 
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >  
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Doug Wegscheid
In reply to this post by EDMONDO SENA
 ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
Do the external appenders come and go, or do we know ahead of time if they are available?



    On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
 
 In order to disable local logging when the external logging is enabled.
So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.


On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:

>  upon examination, I see that clearAppenders() is not public, so that won't work.
> There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
>
>    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote: 


> Can you explain me how can i do it?
>
> Regards.
>
>
>
>
> On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> >
> >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote: 
> > 
> > 
> > Why this instruction goes in UnsupportedOperationException?
> >
> > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > value.clear();
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> > 
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

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

 
Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Matt Sicker
Appenders shouldn't be directly modified like that as it would lead to
a loss of log events during that operation. The appropriate ways to
programmatically initialize configuration is documented here:
https://logging.apache.org/log4j/2.x/manual/customconfig.html#Configurator

On Wed, 25 Mar 2020 at 09:53, Doug Wegscheid <[hidden email]> wrote:

>
>  ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
> Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> Do the external appenders come and go, or do we know ahead of time if they are available?
>
>
>
>     On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:
>
>  In order to disable local logging when the external logging is enabled.
> So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
>
>
> On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> >
> >    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> >
> >
> > Can you explain me how can i do it?
> >
> > Regards.
> >
> >
> >
> >
> > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > >
> > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > >
> > >
> > > Why this instruction goes in UnsupportedOperationException?
> > >
> > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > value.clear();
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



--
Matt Sicker <[hidden email]>

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

EDMONDO SENA
In reply to this post by Doug Wegscheid

1)  Do the external appenders come and go, or do we know ahead of time if they are available?
No, come and go!

2)  Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?

More or less yes.


On 2020/03/25 14:53:08, Doug Wegscheid <[hidden email]> wrote:

>  ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
> Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> Do the external appenders come and go, or do we know ahead of time if they are available?
>
>
>
>     On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
>  
>  In order to disable local logging when the external logging is enabled.
> So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
>
>
> On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> >
> >    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote: 
> > 
> > 
> > Can you explain me how can i do it?
> >
> > Regards.
> >
> >
> >
> >
> > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > >
> > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote: 
> > > 
> > > 
> > > Why this instruction goes in UnsupportedOperationException?
> > >
> > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > value.clear();
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > > 
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> > 
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Matt Sicker
Take a look at this:
https://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender

This appender is extremely flexible for that use case. I'd recommend
avoiding the use of an inline script (JavaScript or Groovy) unless
absolutely necessary as that's likely the slowest routing mechanism
(though you could always benchmark that).

On Wed, 25 Mar 2020 at 09:58, EDMONDO SENA <[hidden email]> wrote:

>
>
> 1)  Do the external appenders come and go, or do we know ahead of time if they are available?
> No, come and go!
>
> 2)  Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
>
> More or less yes.
>
>
> On 2020/03/25 14:53:08, Doug Wegscheid <[hidden email]> wrote:
> >  ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
> > Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> > Do the external appenders come and go, or do we know ahead of time if they are available?
> >
> >
> >
> >     On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> >
> >  In order to disable local logging when the external logging is enabled.
> > So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
> >
> >
> > On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> > >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> > >
> > >    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > >
> > >
> > > Can you explain me how can i do it?
> > >
> > > Regards.
> > >
> > >
> > >
> > >
> > > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > > >
> > > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > > >
> > > >
> > > > Why this instruction goes in UnsupportedOperationException?
> > > >
> > > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > > value.clear();
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


--
Matt Sicker <[hidden email]>

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

EDMONDO SENA
we need only remove all appenders because not necessary in that case.



On 2020/03/25 15:03:26, Matt Sicker <[hidden email]> wrote:

> Take a look at this:
> https://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender
>
> This appender is extremely flexible for that use case. I'd recommend
> avoiding the use of an inline script (JavaScript or Groovy) unless
> absolutely necessary as that's likely the slowest routing mechanism
> (though you could always benchmark that).
>
> On Wed, 25 Mar 2020 at 09:58, EDMONDO SENA <[hidden email]> wrote:
> >
> >
> > 1)  Do the external appenders come and go, or do we know ahead of time if they are available?
> > No, come and go!
> >
> > 2)  Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> >
> > More or less yes.
> >
> >
> > On 2020/03/25 14:53:08, Doug Wegscheid <[hidden email]> wrote:
> > >  ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
> > > Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> > > Do the external appenders come and go, or do we know ahead of time if they are available?
> > >
> > >
> > >
> > >     On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > >
> > >  In order to disable local logging when the external logging is enabled.
> > > So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
> > >
> > >
> > > On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> > > >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > > > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> > > >
> > > >    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > > >
> > > >
> > > > Can you explain me how can i do it?
> > > >
> > > > Regards.
> > > >
> > > >
> > > >
> > > >
> > > > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > > > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > > > >
> > > > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > > > >
> > > > >
> > > > > Why this instruction goes in UnsupportedOperationException?
> > > > >
> > > > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > > > value.clear();
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [hidden email]
> > > > > For additional commands, e-mail: [hidden email]
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
>
> --
> Matt Sicker <[hidden email]>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Doug Wegscheid
In reply to this post by Matt Sicker
Matt, thanks for chiming in. I was running some test cases, and I saw that exact behaviour: lost messages when doing the ctx.update().
 

    On Wednesday, March 25, 2020, 10:58:17 AM EDT, Matt Sicker <[hidden email]> wrote:  
 
 Appenders shouldn't be directly modified like that as it would lead to
a loss of log events during that operation. The appropriate ways to
programmatically initialize configuration is documented here:
https://logging.apache.org/log4j/2.x/manual/customconfig.html#Configurator

On Wed, 25 Mar 2020 at 09:53, Doug Wegscheid <[hidden email]> wrote:

>
>  ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
> Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> Do the external appenders come and go, or do we know ahead of time if they are available?
>
>
>
>    On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:
>
>  In order to disable local logging when the external logging is enabled.
> So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
>
>
> On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> >
> >    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> >
> >
> > Can you explain me how can i do it?
> >
> > Regards.
> >
> >
> >
> >
> > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > >
> > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > >
> > >
> > > Why this instruction goes in UnsupportedOperationException?
> > >
> > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > value.clear();
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



--
Matt Sicker <[hidden email]>

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

 
Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Ralph Goers
In reply to this post by EDMONDO SENA
Are you saying that you are sending the events to one location and want to reconfigure to send them to another location?  The only safe way to do that without losing logging events is to reconfigure - i.e. create a new configuration that replaces the prior configuration. To do what you are asking you would have to first create new appenders with different names and add them to the configuration and start them. Then you would have to remove the Appender references from the LoggerConfigs and add the Appender References to the new Appenders. Note that this cannot be done atomically and you WILL lose logging events while it happens. You would then have to remove the old Appenders and stop them.

Because removing and adding appenders like this cannot be done atomically the Log4j team highly discourages doing it. Instead, create a new configuration and swap it.

Ralph

> On Mar 25, 2020, at 8:05 AM, EDMONDO SENA <[hidden email]> wrote:
>
> we need only remove all appenders because not necessary in that case.
>
>
>
> On 2020/03/25 15:03:26, Matt Sicker <[hidden email]> wrote:
>> Take a look at this:
>> https://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender
>>
>> This appender is extremely flexible for that use case. I'd recommend
>> avoiding the use of an inline script (JavaScript or Groovy) unless
>> absolutely necessary as that's likely the slowest routing mechanism
>> (though you could always benchmark that).
>>
>> On Wed, 25 Mar 2020 at 09:58, EDMONDO SENA <[hidden email]> wrote:
>>>
>>>
>>> 1)  Do the external appenders come and go, or do we know ahead of time if they are available?
>>> No, come and go!
>>>
>>> 2)  Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
>>>
>>> More or less yes.
>>>
>>>
>>> On 2020/03/25 14:53:08, Doug Wegscheid <[hidden email]> wrote:
>>>> ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
>>>> Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
>>>> Do the external appenders come and go, or do we know ahead of time if they are available?
>>>>
>>>>
>>>>
>>>>    On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:
>>>>
>>>> In order to disable local logging when the external logging is enabled.
>>>> So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
>>>>
>>>>
>>>> On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
>>>>> upon examination, I see that clearAppenders() is not public, so that won't work.
>>>>> There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
>>>>>
>>>>>   On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:
>>>>>
>>>>>
>>>>> Can you explain me how can i do it?
>>>>>
>>>>> Regards.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
>>>>>> you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
>>>>>>
>>>>>>   On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:
>>>>>>
>>>>>>
>>>>>> Why this instruction goes in UnsupportedOperationException?
>>>>>>
>>>>>> List<AppenderRef> value = loggerConfig.getAppenderRefs();
>>>>>> value.clear();
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [hidden email]
>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>>
>> --
>> Matt Sicker <[hidden email]>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



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

Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Doug Wegscheid
In reply to this post by Matt Sicker
 Matt's suggestion works. You can make a routing appender that will switch between appenders under program control. Example of something that switches between two different ConsoleAppenders

Configuration:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" packages="org.wegscd">
    <Appenders>
        <Routing name="AB">
            <Routes pattern="${ablookup:ab}">
                <Route key="A">
                    <Console name="ConsoleA">
                        <PatternLayout pattern="ConsoleA %msg%n"/>
                    </Console>
                </Route>
                <Route key="B">
                    <Console name="ConsoleB">
                        <PatternLayout pattern="ConsoleB %msg%n"/>
                    </Console>
                </Route>
            </Routes>
        </Routing>
    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="AB"/>
        </Root>
    </Loggers>
</Configuration>
Component to do the ablookup:
package org.wegscd;

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.lookup.StrLookup;

@Plugin(name = "ablookup", category = StrLookup.CATEGORY)
public class ABLookup implements StrLookup {
    static String ab;
    public ABLookup() {
        System.out.println ("ABLookup instantiated");
    }
    @Override
    public String lookup(String key) {
        if (key.equalsIgnoreCase("ab")) {
            return ab;
        }
        return null;
    }

    @Override
    public String lookup(LogEvent event, String key) {
        return lookup(key);
    }

    public static void setAB(String _ab) {
        ab = _ab;
    }
}

Test Program:  import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wegscd.ABLookup;

public class MainAB {
    static Logger logger;

    public static void main(String[] args) {
        System.setProperty("log4j2.configurationFile", "ab.xml");

        logger = LoggerFactory.getLogger(MainAB.class);

        logger.warn ("Start (goes nowhere, since ab is not set");

        ABLookup.setAB("A");
        logger.info("this should go to ConsoleA");

        ABLookup.setAB("B");
        logger.info("this should go to ConsoleB");

        logger.warn ("Done");
    }
}

Output
 ABLookup instantiated
ConsoleA this should go to ConsoleA
ConsoleB this should go to ConsoleB
ConsoleB Done




    On Wednesday, March 25, 2020, 11:03:48 AM EDT, Matt Sicker <[hidden email]> wrote:  
 
 Take a look at this:
https://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender

This appender is extremely flexible for that use case. I'd recommend
avoiding the use of an inline script (JavaScript or Groovy) unless
absolutely necessary as that's likely the slowest routing mechanism
(though you could always benchmark that).

On Wed, 25 Mar 2020 at 09:58, EDMONDO SENA <[hidden email]> wrote:

>
>
> 1)  Do the external appenders come and go, or do we know ahead of time if they are available?
> No, come and go!
>
> 2)  Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
>
> More or less yes.
>
>
> On 2020/03/25 14:53:08, Doug Wegscheid <[hidden email]> wrote:
> >  ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
> > Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> > Do the external appenders come and go, or do we know ahead of time if they are available?
> >
> >
> >
> >    On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> >
> >  In order to disable local logging when the external logging is enabled.
> > So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
> >
> >
> > On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> > >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> > >
> > >    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > >
> > >
> > > Can you explain me how can i do it?
> > >
> > > Regards.
> > >
> > >
> > >
> > >
> > > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > > >
> > > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote:
> > > >
> > > >
> > > > Why this instruction goes in UnsupportedOperationException?
> > > >
> > > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > > value.clear();
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


--
Matt Sicker <[hidden email]>

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

 
Reply | Threaded
Open this post in threaded view
|

Re: loggerConfig.getAppenderRefs().clear()

Doug Wegscheid
In reply to this post by EDMONDO SENA
 also, would a FailoverAppender with the external appender being the primary be a solution?

    On Wednesday, March 25, 2020, 10:58:16 AM EDT, EDMONDO SENA <[hidden email]> wrote:  
 
 
1)  Do the external appenders come and go, or do we know ahead of time if they are available?
No, come and go!

2)  Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?

More or less yes.


On 2020/03/25 14:53:08, Doug Wegscheid <[hidden email]> wrote:

>  ah. a couple of solutions present themself (and hopefully someone more conversant with log4j4 can chime in).
> Would a RoutingAppender() that knows if external or internal logging is to be done and then routes messages to the appropriate appender a solution?
> Do the external appenders come and go, or do we know ahead of time if they are available?
>
>
>
>    On Wednesday, March 25, 2020, 10:41:33 AM EDT, EDMONDO SENA <[hidden email]> wrote: 

>  In order to disable local logging when the external logging is enabled.
> So, remove all local appenders and disable local logging for re-enabling the delivery towards another system to run-time.
>
>
> On 2020/03/25 14:29:26, Doug Wegscheid <[hidden email]> wrote:
> >  upon examination, I see that clearAppenders() is not public, so that won't work.
> > There is probably a way to do what you want, if you can tell us why you need to clear the appenders.
> >
> >    On Wednesday, March 25, 2020, 10:23:38 AM EDT, EDMONDO SENA <[hidden email]> wrote: 
> > 
> > 
> > Can you explain me how can i do it?
> >
> > Regards.
> >
> >
> >
> >
> > On 2020/03/25 14:18:03, Doug Wegscheid <[hidden email]> wrote:
> > >  you are trying to clear the list of appenderRefs. Are you trying to call clearAppenders() instead of clear()?
> > >
> > >    On Wednesday, March 25, 2020, 10:03:27 AM EDT, EDMONDO SENA <[hidden email]> wrote: 
> > > 
> > > 
> > > Why this instruction goes in UnsupportedOperationException?
> > >
> > > List<AppenderRef> value = loggerConfig.getAppenderRefs();
> > > value.clear();
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > > 
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> > 
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

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