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 Programmatically loading of the configuration file
Date Thu, 22 Jan 2015 16:38:13 GMT
I can't seem to load a configuration file?  The reason I am doing this is because I have my
configuration file in a package that is not on the default classpath.  Adding the package
to the classpath is not straight forward.  Also, I don't want to add a system property or
environment variable because we will be reusing this package throughout all of our projects.
 So the idea is that this package will just be pulled into a project and it will contain the
configuration file along with a class that will add the correct items to the context map and
will load the configuration file.  The developer should just be able to include the package
and they are off and running.

I am using the following code to load the config file which resides in the same package as
the class that this method is part of, but it is not working.  As I step through the code
I can see that inside ConfigurationSource the stream is loaded correctly with the contents
of my file so I know that it found it but when the getContext line is executed I get an error
saying that it could not locate a configuration file.  What am I missing?

        try {
            InputStream is = MyLogFactory.class.getResourceAsStream("log4j2.xml");
            ConfigurationSource source = new ConfigurationSource(is);
            Configuration config = XmlConfigurationFactory.getInstance().getConfiguration(source);
            LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        } catch (IOException ex) {

Thx Blaine

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message