01: /*
02: * AbstractLogProcessor.java
03: *
04: * Created on 26. November 2003, 21:02
05: */
06:
07: package org.jzonic.jlo.processor;
08:
09: import org.jzonic.jlo.*;
10:
11: import java.util.Vector;
12:
13: /**
14: *
15: * @author Administrator
16: */
17: public abstract class AbstractLogProcessor implements LogProcessor {
18:
19: public AbstractLogProcessor() {
20: }
21:
22: public void flush() {
23: }
24:
25: public abstract String getProcessorName();
26:
27: public abstract void processEvent(LogGenerator lg, LogRecord lr);
28:
29: protected void handle(LogEvent le) {
30: if (le.getFormatter() != null) {
31: String msg = le.getFormatter().formatMessage(
32: le.getLogRecord());
33: le.getHandler().publish(msg);
34: } else {
35: le.getHandler().publish(le.getLogRecord());
36: }
37: }
38:
39: protected void handleSpecialChannels(LogRecord lr) {
40: if (lr.getTarget() != null) {
41: if (LogManager.isChannelOn(lr.getTarget().getName(), lr
42: .getConfigurationName())) {
43: Channel myChannel = LogManager.getChannel(lr
44: .getTarget().getName(), lr
45: .getConfigurationName());
46: lr.setTarget(lr.getTarget());
47: LogEvent lec = new LogEvent(myChannel.getLogGenerator()
48: .getHandler(), myChannel.getLogGenerator()
49: .getFormatter(), lr);
50: handle(lec);
51: }
52: }
53: }
54:
55: protected void handlePipes(LogEvent le) {
56: if (LogManager.getInstance().getLogConfiguration(
57: le.getLogRecord().getConfigurationName())
58: .getLogPipesCount() > 0) {
59: Vector pipes = LogManager.getInstance()
60: .getLogConfiguration(
61: le.getLogRecord().getConfigurationName())
62: .getLogPipes();
63: for (int j = 0; j < pipes.size(); j++) {
64: LogPipe pipe = (LogPipe) pipes.get(j);
65: if (pipe.getFilter() != null) {
66: if (pipe.getFilter().match(
67: le.getLogRecord().getMessage())) {
68: LogEvent myEvent = new LogEvent(pipe
69: .getGenerator().getHandler(), pipe
70: .getGenerator().getFormatter(), le
71: .getLogRecord());
72: handle(myEvent);
73: }
74: } else {
75: LogEvent myEvent = new LogEvent(pipe.getGenerator()
76: .getHandler(), pipe.getGenerator()
77: .getFormatter(), le.getLogRecord());
78: handle(myEvent);
79: }
80: }
81: }
82: }
83:
84: }
|