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: Configuration File and programmatic configuration not working
Date Fri, 13 Dec 2019 19:35:21 GMT
Did you also create a CustomConfigurationFactory with an Order value that is larger than the
value in XmlConfigurationFactory?

Ralph

> On Dec 13, 2019, at 11:46 AM, Lohith BK <lohit.b@gmail.com> wrote:
> 
> Greetings,
> 
> I have been trying to get the programmatic configuration working (on top of
> the file based configuration), but it doesn't seem to merge them together.
> Here is the meat of the plugin code.
> /tmp/xpose.log gets created, and also the output from the programmatic
> configuration /tmp/customconfig.xml gets created and looks as expected.
> However when I try to get the configured logger in the code it appears use
> the ones inherited from the root logger. Also, the example code in the
> documentation doesn't seem to reflect the newer builder API.
> 
> https://logging.apache.org/log4j/2.x/manual/customconfig.html
> 
> 
> class CustomConfiguration extends XmlConfiguration{
>    public CustomConfiguration(final LoggerContext loggercontext, final
> ConfigurationSource confsource){
>        super(loggercontext,confsource);
>    }
>    @Override
>    protected void doConfigure(){
>        super.doConfigure();
> 
>        ConfigurationBuilder<BuiltConfiguration> builder =
> ConfigurationBuilderFactory.newConfigurationBuilder();
>        AppenderComponentBuilder apbuilder =
> builder.newAppender("XPOSE","File").addAttribute("fileName","/tmp/xpose.log");
>        builder.add(apbuilder);
>        LoggerComponentBuilder lgbuilder =
> builder.newLogger("customlogger",Level.INFO).addAttribute("additivity","false");
>        lgbuilder.add(builder.newAppenderRef("XPOSE"));
>        builder.add(lgbuilder);
> 
>        try{
>            File opt = new File("/tmp/customconfig.xml");
>            FileOutputStream fop = new FileOutputStream(opt);
>            builder.writeXmlConfiguration(fop);
>            builder.build();
>        }catch(FileNotFoundException e){
>            System.out.println(e.getMessage());
>        }catch(IOException e){
>            System.out.println(e.getMessage());
>        }
>    }
> }
> 
> Output of programmatic configuration.
> 
> <?xml version="1.0" ?>
> <Configuration>
>  <Appenders>
>    <File name="XPOSE" fileName="/tmp/xpose.log"/>
>  </Appenders>
>  <Loggers>
>    <Logger name="customlogger" level="INFO" additivity="false">
>      <AppenderRef ref="XPOSE"/>
>    </Logger>
>  </Loggers>
> </Configuration>



---------------------------------------------------------------------
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