1 | package fr.mael.jiwigo.transverse.util.log4j; |
---|
2 | |
---|
3 | import org.apache.log4j.helpers.FormattingInfo; |
---|
4 | import org.apache.log4j.spi.LoggingEvent; |
---|
5 | |
---|
6 | /** |
---|
7 | * @author mael |
---|
8 | * |
---|
9 | */ |
---|
10 | public class CategoryConcisePatternConverter extends AbstractConcisePatternConverter { |
---|
11 | |
---|
12 | /** |
---|
13 | * |
---|
14 | */ |
---|
15 | private static final int ROLE_LENGTH = 30; |
---|
16 | /** |
---|
17 | * |
---|
18 | */ |
---|
19 | private static final int HINT_LENGTH = 8; |
---|
20 | |
---|
21 | /** |
---|
22 | * |
---|
23 | */ |
---|
24 | private static final int SIZE = 35; |
---|
25 | |
---|
26 | /** |
---|
27 | * Constructeur de CategoryConcisePatternConverter. |
---|
28 | * @param formattingInfo . |
---|
29 | * @param precision . |
---|
30 | */ |
---|
31 | public CategoryConcisePatternConverter(final FormattingInfo formattingInfo, final int precision) { |
---|
32 | super(formattingInfo, precision); |
---|
33 | } |
---|
34 | |
---|
35 | /**. |
---|
36 | * {@inheritDoc} |
---|
37 | */ |
---|
38 | protected final String getConciseName(final LoggingEvent event) { |
---|
39 | final StringBuffer result = new StringBuffer(); |
---|
40 | |
---|
41 | appendConciseCategory(result, event.getLoggerName()); |
---|
42 | |
---|
43 | appendLeftSpaces(result); |
---|
44 | |
---|
45 | return result.toString(); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * @param sb la string a modifier |
---|
50 | * @param loggerName le nom du logger |
---|
51 | */ |
---|
52 | private void appendConciseCategory(final StringBuffer sb, final String loggerName) { |
---|
53 | final int colonIndex = loggerName.indexOf(58); |
---|
54 | |
---|
55 | if (colonIndex == -1) { |
---|
56 | sb.append(simplify(loggerName, ROLE_LENGTH)); |
---|
57 | |
---|
58 | return; |
---|
59 | } |
---|
60 | |
---|
61 | final String roleName = loggerName.substring(0, colonIndex); |
---|
62 | |
---|
63 | final String hintName = loggerName.substring(colonIndex + 1); |
---|
64 | |
---|
65 | // sb.append(simplify(roleName, |
---|
66 | // 20)).append(":").append(simplify(hintName, 8)); |
---|
67 | sb.append(roleName).append(":").append(hintName); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * @param sb la string a modifier |
---|
72 | */ |
---|
73 | private void appendLeftSpaces(final StringBuffer sb) { |
---|
74 | while (sb.length() < SIZE) { |
---|
75 | sb.append(" "); |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|