source: extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/log4j/CategoryConcisePatternConverter.java @ 9387

Last change on this file since 9387 was 9387, checked in by mlg, 13 years ago

First commit for jiwigo-ws-api

File size: 1.8 KB
Line 
1package fr.mael.jiwigo.transverse.util.log4j;
2
3import org.apache.log4j.helpers.FormattingInfo;
4import org.apache.log4j.spi.LoggingEvent;
5
6/**
7 * @author mael
8 *
9 */
10public 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}
Note: See TracBrowser for help on using the repository browser.