logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacob Kjome" <h...@visi.com>
Subject Re: Logging done in the wrong files
Date Fri, 11 Sep 2009 14:33:27 GMT
Please send questions to the user list.  The dev list is for development, not 
user questions.  Note that I've made the switch in my response and CC'd you to 
make sure you see my response.

Are these all running in the same JVM?  Are you using standard classloading or 
specially configuring apps to use parent-last/child-first classloading?  Where 
do you place Log4j?  Where do you place your LogManager code?  I take it you 
have a separate LogManager class for each app?  So you have, for instance, a 
LogManagerWeb class and a LogManagerJava class, each performing Log4j 
configuration in its static initializer?

I would guess that you are probably sharing one big Logger Repository 
(especially if you have Log4j is some common location visible to all the apps) 
and each LogManager class is adding to the configuration.  Keep in mind that, 
by default, configuration in Log4j is cumulative.  However, where two 
configurations have defined the loggers and appenders by the same name, the 
last one configured wins.  This would explain the behavior you see where one 
app logs fine until the other app is initialized and it's log4j configuration 
is added to the repository.

You are actually going about this all wrong.  You either need to isolate 
classloaders and initialize once (and only once, at least if you value your 
sanity) at application startup or you need to use a logger repository 
selector, which allows for dynamic selection of logger repositories based on 
some custom criteria such as JNDI or Thread Context, each maintaining it's own 
configuration.  I wrote about the latter option earlier this week (or maybe 
late last week) on the user list.  Please search for recent posts from me for 
more info.


Jake

On Fri, 11 Sep 2009 06:54:10 -0700 (PDT)
  "S.Kannan" <techy_kans@yahoo.co.in> wrote:
> 
> 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: log4j-dev-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 
> 


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


Mime
View raw message