Your mentions of EAR files make me wonder if the different "applications" are 
running in the same classloader - are they?

Have you put log4j in a common classloader shared by both applications?  This 
might explain what you are seeing - IIRC web containers like WebSphere set up 
hierarchal classloaders for EAR applications, and a class which is loaded from 
the "shared" classloader will be shared by all child classloaders - in other 
words, the same log4j configuration will be used by all child classloaders 
(because there is actually only one instance of the configured log4j classes).

It might be better to configure the specific loggers for each app, such as
log4j.logger.com.yourcompany.web = ...
log4j.logger.com.yourcompany.java = ...

Also, not sure if you realize this but by passing in the log level to your 
logMessage(String strLevel, String Message) wrapper function, you lose any 
possible benefits of guard clauses and overly long messages not having to be 
concatenated by the JVM (http://logging.apache.org/log4j/1.2/faq.html#2.3).

________________________________________
From: S.Kannan [techy_k...@yahoo.co.in]
Sent: Friday, September 11, 2009 11:40 PM
To: log4j-user@logging.apache.org
Subject: Logging done in the wrong files

Hi All, A log4j newbie handling a bigger task .. This is my problem
Hope somebody has got some solution for this.

We have a web application as well as a java application. Both are big enough
. But since both are managing the same business around 3 to 4 ear files are
used in common for both the applications. Since we wanted to classify the
loggers based on the application we have decided to have unique
log.properties file. The following are the configurations in the
log.properties file

for web application
log4j.threshold=ALL
log4j.rootLogger=ALL,INFO_APPENDER,ERROR_APPENDER,DEBUG_APPENDER
log4j.appender.DEBUG_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.DEBUG_APPENDER.MaxBackupIndex=50
log4j.appender.DEBUG_APPENDER.MaxFileSize=10MB
log4j.appender.DEBUG_APPENDER.file=data/tda/logs/Logger_Debug_Web.txt
log4j.appender.DEBUG_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUG_APPENDER.Threshold=DEBUG

for java application
log4j.threshold=ALL
log4j.rootLogger=ALL,INFO_APPENDER,ERROR_APPENDER,DEBUG_APPENDER
log4j.appender.DEBUG_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.DEBUG_APPENDER.MaxBackupIndex=50
log4j.appender.DEBUG_APPENDER.MaxFileSize=10MB
log4j.appender.DEBUG_APPENDER.file=data/tda/logs/Logger_Debug_Java.txt
log4j.appender.DEBUG_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUG_APPENDER.Threshold=DEBUG

The following is the customized log manager class which we have written
public class LogManager {
        String className;
        Logger objLog;

        static {
                InputStream logprops = LogManager.class.getClassLoader()

.getResourceAsStream("path/to/log.properties");
                try {
                        Properties prop = new Properties();
                        prop.load(logProps);
                        PropertyConfigurator.configure(prop);
                } catch (Exception e) {
                        System.out.println("error in  LogManager" +
e.getMessage());
                }
        }

        public LogManager(String className) {
                this.className = className;
                objLog = Logger.getLogger(this.className);
        }

        public void logMessage(String strLevel, String Message) {
                if (strLevel.equals("DEBUG")) {
                        objLog.log(Level.DEBUG, Message);
                } else if (strLevel.equals("INFO")) {
                        objLog.log(Level.INFO, Message);
                } else if (strLevel.equals("WARN")) {
                        objLog.log(Level.WARN, Message);
                } else if (strLevel.equals("ERROR")) {
                        objLog.log(Level.ERROR, Message);
                }
        }
}

And in each class files we have called the logmanager like

private static final LogManager logMgr = new
LogManager(QueueListener.class.getName());
logMgr.logMessage("INFO","QueueListening starts.");

Now our problem is that most of the times the messages in the
Logger_Debug_Java.txt is routed to Logger_Debug_Web.txt once a class which
is common for both application executes. Then the thread or control does not
go back to the Logger_Debug_Java.txt file. Please give me a solution for
this problem

Kannan.S
--
View this message in context: 
http://www.nabble.com/Logging-done-in-the-wrong-files-tp25411329p25411329.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to