Changing the Attributes on a RollingAppender

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

Changing the Attributes on a RollingAppender

Fred Eisele
Given a RollingFileAppender is it possible to dyanamically/programmatically
change its fileName?

        <RollingFile name="X_PLUGIN_FILE"
                     fileName="x.log}"
                     filePattern="x_%i.log}"
                     ignoreExceptions="false">
            <PatternLayout pattern="#linux %file:%method:%line - %msg%n" />
            <OnDemandTriggeringPolicy />
        </RollingFile>

I need to be able to change the log file from my running application plugin.
Reply | Threaded
Open this post in threaded view
|

Re: Changing the Attributes on a RollingAppender

Ralph Goers
No. The file name is immutable.

Ralph

> On Aug 21, 2019, at 6:22 AM, Fred Eisele <[hidden email]> wrote:
>
> Given a RollingFileAppender is it possible to dyanamically/programmatically
> change its fileName?
>
>        <RollingFile name="X_PLUGIN_FILE"
>                     fileName="x.log}"
>                     filePattern="x_%i.log}"
>                     ignoreExceptions="false">
>            <PatternLayout pattern="#linux %file:%method:%line - %msg%n" />
>            <OnDemandTriggeringPolicy />
>        </RollingFile>
>
> I need to be able to change the log file from my running application plugin.



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

Reply | Threaded
Open this post in threaded view
|

Re: Changing the Attributes on a RollingAppender

Fred Eisele
Could construct a new appender and swap it for the old one?

On Wed, Aug 21, 2019 at 8:39 AM Ralph Goers <[hidden email]>
wrote:

> No. The file name is immutable.
>
> Ralph
>
> > On Aug 21, 2019, at 6:22 AM, Fred Eisele <[hidden email]>
> wrote:
> >
> > Given a RollingFileAppender is it possible to
> dyanamically/programmatically
> > change its fileName?
> >
> >        <RollingFile name="X_PLUGIN_FILE"
> >                     fileName="x.log}"
> >                     filePattern="x_%i.log}"
> >                     ignoreExceptions="false">
> >            <PatternLayout pattern="#linux %file:%method:%line - %msg%n"
> />
> >            <OnDemandTriggeringPolicy />
> >        </RollingFile>
> >
> > I need to be able to change the log file from my running application
> plugin.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Changing the Attributes on a RollingAppender

Ralph Goers
You can’t atomically swap an appender. If you remove it and then add a new one with the same name you will lose log events targeted at the appender while it is removed. You could add a new appender with a different name and then modify all the loggers using the old one to use the new one, but Log4j won’t do that for you.

What problem are you trying to solve?  Log4j might already have a different way of supporting it.

Ralph

> On Aug 21, 2019, at 10:44 AM, Fred Eisele <[hidden email]> wrote:
>
> Could construct a new appender and swap it for the old one?
>
> On Wed, Aug 21, 2019 at 8:39 AM Ralph Goers <[hidden email]>
> wrote:
>
>> No. The file name is immutable.
>>
>> Ralph
>>
>>> On Aug 21, 2019, at 6:22 AM, Fred Eisele <[hidden email]>
>> wrote:
>>>
>>> Given a RollingFileAppender is it possible to
>> dyanamically/programmatically
>>> change its fileName?
>>>
>>>       <RollingFile name="X_PLUGIN_FILE"
>>>                    fileName="x.log}"
>>>                    filePattern="x_%i.log}"
>>>                    ignoreExceptions="false">
>>>           <PatternLayout pattern="#linux %file:%method:%line - %msg%n"
>> />
>>>           <OnDemandTriggeringPolicy />
>>>       </RollingFile>
>>>
>>> I need to be able to change the log file from my running application
>> plugin.
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: Changing the Attributes on a RollingAppender

Fred Eisele
I have an acceptable solution.
I use the appender-manager and change the filePattern via
        this.appendManager.setPatternProcessor( new PatternProcessor(
filePattern, this.appendManager.getPatternProcessor() ) );
Similarly (using a custom strategy) I change the base fileName.
Of course the appender object does not reflect these changes but it suits
my needs.

On Wed, Aug 21, 2019 at 1:27 PM Ralph Goers <[hidden email]>
wrote:

> You can’t atomically swap an appender. If you remove it and then add a new
> one with the same name you will lose log events targeted at the appender
> while it is removed. You could add a new appender with a different name and
> then modify all the loggers using the old one to use the new one, but Log4j
> won’t do that for you.
>
> What problem are you trying to solve?  Log4j might already have a
> different way of supporting it.
>

I need to be able to change the log fileName and filePattern associated
with a specific RollingAppender from my running application plugin.
Is there a way to get an appender directly by name?


> Ralph
>
> > On Aug 21, 2019, at 10:44 AM, Fred Eisele <[hidden email]>
> wrote:
> >
> > Could construct a new appender and swap it for the old one?
> >
> > On Wed, Aug 21, 2019 at 8:39 AM Ralph Goers <[hidden email]>
> > wrote:
> >
> >> No. The file name is immutable.
> >>
> >> Ralph
> >>
> >>> On Aug 21, 2019, at 6:22 AM, Fred Eisele <[hidden email]>
> >> wrote:
> >>>
> >>> Given a RollingFileAppender is it possible to
> >> dyanamically/programmatically
> >>> change its fileName?
> >>>
> >>>       <RollingFile name="X_PLUGIN_FILE"
> >>>                    fileName="x.log}"
> >>>                    filePattern="x_%i.log}"
> >>>                    ignoreExceptions="false">
> >>>           <PatternLayout pattern="#linux %file:%method:%line - %msg%n"
> >> />
> >>>           <OnDemandTriggeringPolicy />
> >>>       </RollingFile>
> >>>
> >>> I need to be able to change the log file from my running application
> >> plugin.
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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: Changing the Attributes on a RollingAppender

Carter Kozak-2
Have you considered using a routing appender[1]? It can write to a specific file based on jvm system properties, thread context (MDC), or any other pattern parameter.

1. https://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender

On Thu, Aug 22, 2019, at 08:49, Fred Eisele wrote:

> I have an acceptable solution.
> I use the appender-manager and change the filePattern via
>  this.appendManager.setPatternProcessor( new PatternProcessor(
> filePattern, this.appendManager.getPatternProcessor() ) );
> Similarly (using a custom strategy) I change the base fileName.
> Of course the appender object does not reflect these changes but it suits
> my needs.
>
> On Wed, Aug 21, 2019 at 1:27 PM Ralph Goers <[hidden email]>
> wrote:
>
> > You can’t atomically swap an appender. If you remove it and then add a new
> > one with the same name you will lose log events targeted at the appender
> > while it is removed. You could add a new appender with a different name and
> > then modify all the loggers using the old one to use the new one, but Log4j
> > won’t do that for you.
> >
> > What problem are you trying to solve? Log4j might already have a
> > different way of supporting it.
> >
>
> I need to be able to change the log fileName and filePattern associated
> with a specific RollingAppender from my running application plugin.
> Is there a way to get an appender directly by name?
>
>
> > Ralph
> >
> > > On Aug 21, 2019, at 10:44 AM, Fred Eisele <[hidden email]>
> > wrote:
> > >
> > > Could construct a new appender and swap it for the old one?
> > >
> > > On Wed, Aug 21, 2019 at 8:39 AM Ralph Goers <[hidden email]>
> > > wrote:
> > >
> > >> No. The file name is immutable.
> > >>
> > >> Ralph
> > >>
> > >>> On Aug 21, 2019, at 6:22 AM, Fred Eisele <[hidden email]>
> > >> wrote:
> > >>>
> > >>> Given a RollingFileAppender is it possible to
> > >> dyanamically/programmatically
> > >>> change its fileName?
> > >>>
> > >>> <RollingFile name="X_PLUGIN_FILE"
> > >>> fileName="x.log}"
> > >>> filePattern="x_%i.log}"
> > >>> ignoreExceptions="false">
> > >>> <PatternLayout pattern="#linux %file:%method:%line - %msg%n"
> > >> />
> > >>> <OnDemandTriggeringPolicy />
> > >>> </RollingFile>
> > >>>
> > >>> I need to be able to change the log file from my running application
> > >> plugin.
> > >>
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> 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]
> >
> >
>