Great! Glad to be of help. Remko On Monday, February 10, 2014, McCarthy, Peter (Peter) <[email protected]> wrote:
> Hi Remko, > > Yes this is exactly what I was looking for, and it does save me a large > amount of effort. thanks you very much for the very useful feedback. > > Regards > Peter > > ________________________________________ > From: Remko Popma [[email protected] <javascript:;>] > Sent: 07 February 2014 18:15 > To: Log4J Users List > Subject: Re: Loading multiple different xml configuration files from > different components within process > > Peter, > > I did not fully understand what you are trying to achieve, so I may be > completely off the mark, but are you aware that Log4J supports XInclude for > XML configurations? See also: > https://issues.apache.org/jira/browse/LOG4J2-341 > > This may be much, much easier than trying to approach this > programmatically. > > Hope this helps, > -Remko > > > > > On Wed, Feb 5, 2014 at 7:24 PM, McCarthy, Peter (Peter) > <[email protected]>wrote: > > > Sorry folks, > > > > The commented out bit of code in first post may be misleading. I have > > corrected it below. When I use the command line > -Dlog4j.configurationFile, > > I leave the static block out of the program. > > > > Again all help appreciated... > > > > Regards > > Peter > > > > -----Original Message----- > > From: McCarthy, Peter (Peter) > > Sent: 05 February 2014 09:34 > > To: Log4J Users List > > Subject: Loading multiple different xml configuration files from > different > > components within process > > > > Folks, > > > > I am trying to programmatically configure multiple xml files as I want > > each sub system using log4j2 to "own" its own configuration (As opposed > to > > having them all in one monolithic block). > > > > I have tried the code below with an xml that reconfigures the root logger > > to a separate file. When I load the config file from the command line > > (-Dlog4j.configuration) everything works fine. However when loaded using > > the code below, the output goes to the default root logger. When I look > at > > the log4j logs themselves it states that is has set up the root logger > > using my appender, however the log statements do NOT go to my appender. > > > > The relevant config is also included. Any help is greatly appreciated !! > > > > Regards > > Peter McCarthy > > > > public class MyLogger { > > > > private static Logger logger; > > > > static { > > File logConfigFile = new File( "log4j2_SGM.xml" ); > > try { > > FileInputStream fis = new FileInputStream( logConfigFile ); > > XMLConfigurationFactory fc = new XMLConfigurationFactory( ); > > fc.getConfiguration( new > > ConfigurationFactory.ConfigurationSource( fis ) ); > > > > URI configuration = logConfigFile.toURI(); > > Configurator.initialize("config", null, configuration); > > > > org.apache.logging.log4j.core.LoggerContext ctx = > > (org.apache.logging.log4j.core.LoggerContext) > > LogManager.getContext( true ); > > ctx.reconfigure(); > > } catch (FileNotFoundException e) { > > e.printStackTrace(); > > } > > > > logger = LogManager.getLogger(MyLogger.class); > > } > > > > /** > > * @param args > > */ > > public static void main(String[] args) { > > int myNum = 0; > > > > while (true) { > > logger.error("Hello, World! ", myNum++); > > if ( myNum == 10 ) { > > break; > > } > > } > > } > > > > } > > > > <?xml version="1.0" encoding="UTF-8"?> > > <Configuration status="all" dest="file://C:/Avaya/Logs/CCMS/log4j2.log"> > > <Properties> > > <Property name="AmlTransLogLoggingLevel">DEBUG</Property> > > <Property name="AmlTransLogLoggingLevel">DEBUG</Property> > >
