01: package com.jamonapi.log4j;
02:
03: import java.util.Properties;
04:
05: import org.apache.log4j.PropertyConfigurator;
06: import org.apache.log4j.Logger;
07: import com.jamonapi.MonitorFactory;
08:
09: import com.jamonapi.utils.Misc;
10:
11: public class Log4jTester {
12:
13: private static Properties getDefaultProps() {
14: // # Set root logger level to DEBUG and its only appender to A1.
15: Properties properties = new Properties();
16: properties.put("log4j.logger.com.jamonapi.log4j",
17: "DEBUG, A1, jamonAppender");
18:
19: // # A1 is set to be a ConsoleAppender, and A2 uses JAMonAppender.
20: properties.put("log4j.appender.A1",
21: "org.apache.log4j.ConsoleAppender");
22:
23: properties.put("log4j.appender.jamonAppender",
24: "com.jamonapi.log4j.JAMonAppender");
25:
26: properties.put("log4j.appender.jamonAppender.units",
27: "testlog4jUnits");
28: properties
29: .put(
30: "log4j.appender.jamonAppender.enableDefaultGeneralizer",
31: "true");
32:
33: properties.put("log4j.appender.jamonAppender.EnableListeners",
34: "BASIC");
35: properties.put(
36: "log4j.appender.jamonAppender.EnableListenerDetails",
37: "true");
38:
39: properties.put(
40: "log4j.appender.jamonAppender.EnableLevelMonitoring",
41: "true");
42: properties.put(
43: "log4j.appender.jamonAppender.ListenerBufferSize",
44: "200");
45:
46: // # jamonAppender uses PatternLayout.
47: properties.put("log4j.appender.A1.layout",
48: "org.apache.log4j.PatternLayout");
49: properties.put("log4j.appender.A1.layout.ConversionPattern",
50: "%-4r steve [%t] %-5p %c %x - %m%n");
51:
52: // # A1 uses PatternLayout.
53: properties.put("log4j.appender.jamonAppender.layout",
54: "org.apache.log4j.PatternLayout");
55: properties
56: .put(
57: "log4j.appender.jamonAppender.layout.ConversionPattern",
58: "%p.%c.%m");
59:
60: return properties;
61: }
62:
63: public static void main(String[] args) throws Exception {
64: PropertyConfigurator.configure(getDefaultProps());
65: Logger log1 = Logger.getLogger("com.jamonapi.log4j");
66:
67: for (int i = 0; i < 5; i++) {
68: log1.debug("message " + i);
69: log1.error("message " + i);
70: log1.info("message " + i);
71: }
72:
73: Misc.disp(MonitorFactory.getRootMonitor().getData());
74:
75: for (int i = 0; i < 5; i++) {
76: log1.debug("message " + i);
77: log1.error("message " + i);
78: log1.info("message " + i);
79: }
80: Misc.disp(MonitorFactory.getRootMonitor().getData());
81:
82: }
83: }
|