John,

This was the solution that I came up with to be able to load a configuration 
file that was not on the class path.  I have since had to update the code to 
work correctly with a NetBeans RCP application.  If I understand you correctly 
this solution will not work for you because you don't want a configuration file 
at all while I did want a configuration file but I wanted the file hidden 
within the project and not modified afterwards.

Blaine

-----Original Message-----
From: John Lussmyer [mailto:[email protected]] 
Sent: Tuesday, February 03, 2015 10:47 AM
To: [email protected]
Subject: Configuring Log4J without a file - FAQ needs update

I have a situation where I can't have a configuration file, so I want to 
configure Log4J programmatically.
The FAQ on this "How do I configure log4j2 in code without a configuration 
file?<http://logging.apache.org/log4j/2.x/faq.html#config_from_code>" is rather 
unclear, as it suggests using a method that takes a file name.
Shouldn't it suggest the one that takes a ConfigurationSource?

I recently found this:
        InputStream is = MyLogFactory.class.getResourceAsStream("log4j2.xml");
        ConfigurationSource source = new ConfigurationSource(is);
        Configurator.initialize(MyLogFactory.class.getClassLoader(), source);

Is this the proper technique to use in this case?


________________________________
Confidentiality notice: This message may contain confidential information. It 
is intended only for the person to whom it is addressed. If you are not that 
person, you should not use this message. We request that you notify us by 
replying to this message, and then delete all copies including any contained in 
your reply. Thank you.

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

Reply via email to