logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rossi <s...@electroteque.org>
Subject Programatically set appenders
Date Thu, 04 Oct 2007 09:23:09 GMT
Hi there, im in a bit of a dilemma at the moment. Im running a spring  
based web application and id like to dynamically set appenders / log  
files for each context path on each access to the webapp. The problem  
is this bit of code works however the header is created each time the  
class is run to do the access logging. Ive built a custom log4j  
package to do W3C logging from the statistics API of this webapp. I  
want to try and avoid setting appenders and loggers for every context  
path or else it would be a nightmare to manage. I'm hoping to only  
load the appender for each context once it seems it gets restarted on  
each call.

I have this at the top of my class

private static final W3CLogger logStats = (W3CLogger)  
W3CLogger.getLogger(StreamStatisticsLog.class.getName());
	private RollingFileAppender appender = new RollingFileAppender();
	private TimeBasedRollingPolicy policy = new TimeBasedRollingPolicy();
	private W3CLayout layout = new W3CLayout();

then this method is called to do the logging, it works fine however  
obviouslly the appender calls the header each time.

public void streamComplete(ISubscriberStream stream)
{
		IStreamCapableConnection conn = stream.getConnection();
		
     		appender.setName(conn.getScope().getName() + "W3C-APP");
     		appender.setLayout(layout);
     		policy.setFileNamePattern(logPath + conn.getScope().getParent 
().getName() + "/stats/" + conn.getScope().getName() + "/Red5_%d 
{yyyyMMdd}.log");
     		appender.setRollingPolicy(policy);
     		logStats.addAppender(appender);
     		appender.activateOptions();
		
		
		IPlaylistSubscriberStream streamStats = (IPlaylistSubscriberStream)  
stream;
		getStats(streamStats, conn);
		logStats.stop(values);
}

Any ideas how to archieve something similar with adding everything at  
startup in log4j.xml ? I have one config set for it right now which  
is the class doing the logging

<logger name="org.red5.server.logging.statistics.StreamStatisticsLog"  
class="org.red5.server.logging.W3CLogger">
		<level value="PLAYBACKSTOP#org.red5.server.logging.W3CLevel"/>		
</logger>

Is what im trying to archieve scalable, would there be any threading  
performance problems doing it like this ? Any feedback on how to  
programmically achieve what im trying to do would be great thanks.




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message