logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hstanciu <hstan...@yahoo.com>
Subject logging different object instances in different log files
Date Thu, 12 Mar 2009 14:13:42 GMT

Hello!

I have an object that models a business flow, let's say BizFlowObj(int
BizFlowNumber).
I want to log whatever is happening in one flow to one log, and another flow
in another log (that means I want logging for an instance of a class and the
classes used by that instance in one log file, and another instance of that
class in a different file).


I tried like this:

private void initializeFlowBasedLogging(int flowNum){
	
		
		//Logger rootLogger = Logger.getRootLogger();
		Appender appender = null;
		logger.removeAllAppenders();
		logger.setAdditivity(false);
		try {
			PatternLayout patternLayout = new PatternLayout();
			patternLayout.setConversionPattern("%d %-5p [%c] %m%n");
			appender = new FileAppender(patternLayout,"log_flow_no_"+flowNum+".log");
			
		} catch (IOException e) {
			logger.warn("Could not initialize the flow dependent logging; the logging
will be writeen in the same file.");
		}
		if(null != appender){
			logger.addAppender(appender);
		}
		
	}

And then for BizFlowObj 

private Logger logger = Logger.getLogger("com.firma.mainPackage");

For all the objects that will be build inside BizFlowObj I got loggers like

private Logger logger =
Logger.getLogger("com.firma.mainPackage.subPackageXXXX");

I am having two logging files, in log1.txt BizFlowObj1 is writing for a
short period of time things related to
BizFlowObj1 and then stops and in log2.txt there is data written from
BizFlowObj2 AND BizFlowObj1.

Do you have any idea how could I separate the two logs?

Thanks,
Horatiu



-- 
View this message in context: http://www.nabble.com/logging-different-object-instances-in-different-log-files-tp22477243p22477243.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
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