logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Blaine Bergeson (bbergeson)" <bberge...@micron.com>
Subject RE: Configuring Log4J without a file - FAQ needs update
Date Tue, 03 Feb 2015 18:47:09 GMT

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.


-----Original Message-----
From: John Lussmyer [mailto:John.Lussmyer@efi.com] 
Sent: Tuesday, February 03, 2015 10:47 AM
To: log4j-user@logging.apache.org
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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message