logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: Getter method for retrieving the attributes of an appender from the LoggerContext
Date Tue, 26 Jan 2016 20:03:24 GMT
Not exactly. You can do:

Appender appender = ctx.getConfiguration().getAppender(“syslogAppender”);

then you would have to do 

SyslogAppender syslogAppender = (SyslogAppender) appender;

normally you would probably use instanceof to verify it is actually a SyslogAppender.

Once you have that you can call whatever methods the SyslogAppender exposes for getting its
attributes. They are not stored in a Map however, so you can’t just call a generic getAttribute
method.

Ralph


> On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <ap.giannakidis@gmail.com>
wrote:
> 
> Hello team,
> 
> I have created a logger with an appender using the ConfigurationBuilder and
> the AppenderComponentBuilder.
> 
> Let's say that this is how I create my appender:
> 
> AppenderComponentBuilder appenderBuilder =
>                builder.newAppender( "syslogAppender", "Syslog" )
>                .addAttribute( "protocol", "TCP" )
>                .addAttribute( "host", "localhost" )
>                .addAttribute( "port", 514 )
>                .addAttribute( "facility", "LOCAL2" )
>                .addAttribute( "immediateFlush", true )
>                .addAttribute( "newLine", true );
> 
> Then, after I finish creating the builder I use the
> Configurator.initialize( builder.build() ) to get the LoggerContext.
> 
> Is there any way I can access the attributes of the appender through the
> LoggerContext?
> 
> For example something like this:
> 
> LoggerContext ctx = Configurator.initialize( builder.build() );
> 
> String hostname =
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> 
> Thank you all very much for your help.
> 
> Apostolis



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


Mime
View raw message