OK. I see that I should have looked at the code in your configuration class more closely. By the time doConfigure() is called the Configuration object has already been created. You are creating a ConfigurationBuilder and building a new Configuration. But the configuration you are building won’t be saved anywhere nor will it be merged with the Configuration your class is extending.
If you look at the example, it accesses the configuration objects that have been built, creates new ones, and adds them to the current Configuration class. In other words, you shouldn’t be using ConfigurationBuilder to modify an existing configuration. Use the Builders or factory classes of the components you want to add and directly add them to your Configuration. Ralph > On Dec 13, 2019, at 12:55 PM, Lohith BK <lohi...@gmail.com> wrote: > > Yes I did. XmlConfigurationFactory has an order value of 5. > > @Plugin( > name="confplugin", > category = "ConfigurationFactory") > @Order(6) > > public class CustomConfigurationFactory extends ConfigurationFactory{ > > @Override > public Configuration getConfiguration(final LoggerContext > loggercontext, final ConfigurationSource confsource){ > return new CustomConfiguration(loggercontext,confsource); > } > > @Override > public String[] getSupportedTypes(){ > return new String[] {"*",".xml"}; > } > } > > On Fri, Dec 13, 2019 at 11:35 AM Ralph Goers <ralph.go...@dslextreme.com> > wrote: > >> 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 <lohi...@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-unsubscr...@logging.apache.org >> For additional commands, e-mail: log4j-user-h...@logging.apache.org >> >> --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org