1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.pattern;
19
20
21 /***
22
23 <p>PatternConverter is an abstract class that provides the
24 formatting functionality that derived classes need.
25
26 <p>Conversion specifiers in a conversion patterns are parsed to
27 individual PatternConverters. Each of which is responsible for
28 converting an object in a converter specific manner.
29
30 @author <a href="mailto:cakalijp@Maritz.com">James P. Cakalic</a>
31 @author Ceki Gülcü
32 @author Chris Nokes
33 @author Curt Arnold
34
35 */
36 public abstract class PatternConverter {
37 /***
38 * Converter name.
39 */
40 private final String name;
41
42 /***
43 * Converter style name.
44 */
45 private final String style;
46
47 /***
48 * Create a new pattern converter.
49 * @param name name for pattern converter.
50 * @param style CSS style for formatted output.
51 */
52 protected PatternConverter(final String name, final String style) {
53 this.name = name;
54 this.style = style;
55 }
56
57 /***
58 * Formats an object into a string buffer.
59 * @param obj event to format, may not be null.
60 * @param toAppendTo string buffer to which the formatted event will be appended. May not be null.
61 */
62 public abstract void format(final Object obj, final StringBuffer toAppendTo);
63
64 /***
65 * This method returns the name of the conversion pattern.
66 *
67 * The name can be useful to certain Layouts such as HTMLLayout.
68 *
69 * @return the name of the conversion pattern
70 */
71 public final String getName() {
72 return name;
73 }
74
75 /***
76 * This method returns the CSS style class that should be applied to
77 * the LoggingEvent passed as parameter, which can be null.
78 *
79 * This information is currently used only by HTMLLayout.
80 *
81 * @param e null values are accepted
82 * @return the name of the conversion pattern
83 */
84 public String getStyleClass(Object e) {
85 return style;
86 }
87 }