Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dc1a86e84a1dafa82ec7d2bcc5e0b538eaf27ed1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.eclipse.jetty.util.log;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class NamedLogTest
{
    private static Logger originalLogger;

    @SuppressWarnings("deprecation")
    @BeforeClass
    public static void rememberOriginalLogger()
    {
        originalLogger = Log.getLog();
    }

    @AfterClass
    public static void restoreOriginalLogger()
    {
        Log.setLog(originalLogger);
    }

    @Test
    public void testNamedLogging()
    {
        Red red = new Red();
        Green green = new Green();
        Blue blue = new Blue();

        StdErrCapture output = new StdErrCapture();

        setLoggerOptions(Red.class,output);
        setLoggerOptions(Green.class,output);
        setLoggerOptions(Blue.class,output);

        red.generateLogs();
        green.generateLogs();
        blue.generateLogs();

        output.assertContains(Red.class.getName());
        output.assertContains(Green.class.getName());
        output.assertContains(Blue.class.getName());
    }

    private void setLoggerOptions(Class<?> clazz, StdErrCapture output)
    {
        Logger logger = Log.getLogger(clazz);
        logger.setDebugEnabled(true);

        if (logger instanceof StdErrLog)
        {
            StdErrLog sel = (StdErrLog)logger;
            sel.setPrintLongNames(true);
            output.capture(sel);
        }
    }
}

Back to the top