Hello there,

 

I have started the migration process for a few of our applications running
on Weblogic 10.3.3 to Log4j 2.0. I am running into a few issues that I hope
someone can help me with.

 

Since all the apps are running within 1 JVM, each app is to read its own
log4j configuration and write to its own log file. To achieve this, I am
doing the following:

 

    private static void configure()

    {

        try

        {

            LoggerContext ctx = (LoggerContext)
LogManager.getContext(false);

            System.out.println("Original Config Name: " +
ctx.getConfiguration().getName());

 

            java.io.InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream(Constants
.PROP_LOG4J_FILENAME);

            InputSource isource = new InputSource(is);

            

            File file;

            URL url =
Thread.currentThread().getContextClassLoader().getResource(Constants.PROP_LO
G4J_FILENAME);

            try {

                file = new File(url.toURI());

            } catch(URISyntaxException e) {

                file = new File(url.getPath());

            }

            

            XMLConfiguration newConfig = new XMLConfiguration(isource,
file);

            System.out.println("New Config Name: " + newConfig.getName());

 

            ctx.setConfiguration(newConfig);

            ctx.reconfigure();

            System.out.println("CTX isReady: " + ctx.isStarted());

            

            Map<String, Appender> map =
ctx.getConfiguration().getAppenders();

            System.out.println("Current Config Map Size: " + map.size());

            System.out.println("Current Config Name: " +
ctx.getConfiguration().getName());

        }

        catch(Exception ex)

        {

            ex.printStackTrace();

        }

    }

 

The System output I get is as follows:

 

Original Config Name: Default

New Config Name: AccessService

CTX isReady: true

Current Config Map Size: 1

Current Config Name: Default

 

This tells me that the ctx.setConfiguration(newConfig) and the
ctx.reconfigure() did not actually take in the new configuration as
presented by the XMLConfiguration. How do I go about resolving this? 

 

I don't want to set a system level property since that will be applicable to
the entire VM and my loggers append to different log files rather than the
intended one. Please help me as I have been stuck on this for the past 4
days. I appreciate any pointers you can offer.

 

Thanks,

Viral Shah

AIM: budmiller75

Yahoo/Skype: virals3

 

 

Reply via email to