1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.rule;
19
20 import java.awt.Color;
21 import java.io.Serializable;
22
23 import org.apache.log4j.spi.LoggingEvent;
24
25
26 /***
27 * A Rule class which also holds a color.
28 *
29 * @author Scott Deboy (sdeboy@apache.org)
30 */
31 public class ColorRule extends AbstractRule implements Serializable {
32 /***
33 * Serialization id.
34 */
35 static final long serialVersionUID = -794434783372847773L;
36
37 /***
38 * Wrapped rule.
39 */
40 private final Rule rule;
41 /***
42 * Foreground color.
43 */
44 private final Color foregroundColor;
45 /***
46 * Background color.
47 */
48 private final Color backgroundColor;
49 /***
50 * Expression.
51 */
52 private final String expression;
53
54 /***
55 * Create new instance.
56 * @param expression expression.
57 * @param rule rule.
58 * @param backgroundColor background color.
59 * @param foregroundColor foreground color.
60 */
61 public ColorRule(final String expression,
62 final Rule rule,
63 final Color backgroundColor,
64 final Color foregroundColor) {
65 super();
66 this.expression = expression;
67 this.rule = rule;
68 this.backgroundColor = backgroundColor;
69 this.foregroundColor = foregroundColor;
70 }
71
72 /***
73 * Get rule.
74 * @return underlying rule.
75 */
76 public Rule getRule() {
77 return rule;
78 }
79
80 /***
81 * Get foreground color.
82 * @return foreground color.
83 */
84 public Color getForegroundColor() {
85 return foregroundColor;
86 }
87
88 /***
89 * Get background color.
90 * @return background color.
91 */
92 public Color getBackgroundColor() {
93 return backgroundColor;
94 }
95
96 /***
97 * Get expression.
98 * @return expression.
99 */
100 public String getExpression() {
101 return expression;
102 }
103
104 /***
105 * {@inheritDoc}
106 */
107 public boolean evaluate(final LoggingEvent event) {
108 return (rule != null && rule.evaluate(event));
109 }
110
111 /***
112 * {@inheritDoc}
113 */
114 public String toString() {
115 StringBuffer buf = new StringBuffer("color rule - expression: ");
116 buf.append(expression);
117 buf.append(", rule: ");
118 buf.append(rule);
119 buf.append(" bg: ");
120 buf.append(backgroundColor);
121 buf.append(" fg: ");
122 buf.append(foregroundColor);
123 return buf.toString();
124 }
125 }