01: package org.jzonic.jlo.processor;
02:
03: import java.io.InputStream;
04: import java.util.Properties;
05:
06: /**
07: * This class instantiates the specific LogProcessor. This LogProcessor
08: * is defined in the jlo.properties as
09: * <pre>
10: * processor=direct
11: * </pre>
12: * for direct processing or
13: * <pre>
14: * processor=asynchronous
15: * </pre>
16: * for asynchronous logging. If the property is not set then the
17: * asynchronous LogProcessor is used by default.
18: *
19: * @author Andreas Mecky andreas.mecky@xcom.de
20: * @author Terry Dye terry.dye@xcom.de
21: */
22: public class LogProcessorFactory {
23:
24: private static LogProcessor lp = null;
25: private static LogProcessorFactory lpf = null;
26:
27: private LogProcessorFactory() {
28: try {
29: ClassLoader cl = this .getClass().getClassLoader();
30: InputStream fis = cl.getResourceAsStream("jlo.properties");
31: if (fis == null) {
32: lp = new AsynchronousLogProcessor();
33: } else {
34: Properties properties = new Properties();
35: properties.load(fis);
36: String ptype = properties.getProperty("processor");
37: if (ptype != null) {
38: if (ptype.equalsIgnoreCase("direct")) {
39: lp = new DirectLogProcessor();
40: } else {
41: lp = new AsynchronousLogProcessor();
42: }
43: } else {
44: lp = new AsynchronousLogProcessor();
45: }
46: }
47: } catch (Exception e) {
48: lp = new AsynchronousLogProcessor();
49: }
50:
51: }
52:
53: public static LogProcessor getLogProcessor() {
54: if (lpf == null) {
55: lpf = new LogProcessorFactory();
56: }
57: return lp;
58: }
59:
60: public void flush() {
61: lp.flush();
62: }
63:
64: }
|