Your problem is a classloader issue. Keep in mind that the Logger-Universe 
which you initialize within your static method is globally the same within the 
same classloader. Annother classloader would initialize another 
logger-universe. You have to elaborate which class is loaded by which 
classloader. This depends on the application server you use, its configuration 
and your deployment.
Search the archives for "MultiFileAppender" and "RepositorySelector". There are 
plenty of ideas how to separate log files depending on the context.
BTW: this (log4j-dev) is the mailing list of the log4j developers. Questions on 
how to use log4j should be asked on the log4j mailing list.
Heri

-----Ursprüngliche Nachricht-----
Von: S.Kannan [mailto:[email protected]] 
Gesendet: Freitag, 11. September 2009 15:54
An: [email protected]
Betreff: 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-tp25401380p25401380.html
Sent from the Log4j - Dev mailing list archive at Nabble.com.


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


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

Reply via email to