Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5827 amar.kumar 1
/*
2
 *	Copyright 2005 stat4j.org
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *	You may obtain a copy of the License at
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
 
17
package net.sourceforge.stat4j.log4j;
18
 
19
import net.sourceforge.stat4j.filter.LogInterceptor;
20
import net.sourceforge.stat4j.filter.MetricCollector;
21
import net.sourceforge.stat4j.util.Util;
22
 
23
import org.apache.log4j.AppenderSkeleton;
24
import org.apache.log4j.spi.LoggingEvent;
25
 
26
 
27
/**
28
 * Name:		Stat4JAppender.java
29
 * Date:		Sep 1, 2004
30
 * Description:
31
 * 
32
 * This log4j Appender is responsible for forwarding on all
33
 * log messages to the stat4j regexp statstic engine.
34
 * 
35
 * Logs from stat4j classes will be ignored.
36
 * 
37
 * @author Lara D'Abreo
38
 */
39
public class Stat4jAppender extends AppenderSkeleton {
40
 
41
	protected static String c;
42
 
43
	public Stat4jAppender() {
44
 
45
		c = Util.getCategory();
46
 
47
	}
48
 
49
	protected void append(LoggingEvent logEvent) {
50
		// dont scrap our own logs
51
		if (logEvent.categoryName.equals(c))
52
			return;
53
		if(LogInterceptor.shouldProcessLog(logEvent.getRenderedMessage())) {
54
//			 direct log to metric capture mechanism
55
	        Throwable cause = (logEvent.getThrowableInformation() == null)? null : logEvent.getThrowableInformation().getThrowable();
56
			MetricCollector.getInstance().applyLog(logEvent.getRenderedMessage(), cause);
57
		}
58
	}
59
 
60
	public boolean requiresLayout() {
61
		return false;
62
	}
63
 
64
	public void close() {
65
		MetricCollector.getInstance().close();
66
 
67
	}
68
 
69
}