aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/logging/LevelsModSpecTest.java
blob: d987c210b4a05fab02161128849f1b73da5208e5 (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
59
60
61
62
63
64
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.logging;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author arnej
 */
public class LevelsModSpecTest {

    @Test
    public void hasCorrectDefault() {
        String wanted = "fatal=on,error=on,warning=on,info=on,event=on,config=on,debug=off,spam=off";
        var l = new LevelsModSpec();
        assertEquals(wanted, l.toLogctlModSpec());
    }

    @Test
    public void canTurnInfoOff() {
        String wanted = "fatal=on,error=on,warning=on,info=off,event=on,config=on,debug=off,spam=off";
        var l = new LevelsModSpec();
        l.setLevels("-info");
        assertEquals(wanted, l.toLogctlModSpec());
    }

    @Test
    public void canTurnDebugOn() {
        String wanted = "fatal=on,error=on,warning=on,info=on,event=on,config=on,debug=on,spam=off";
        var l = new LevelsModSpec();
        l.setLevels("+debug");
        assertEquals(wanted, l.toLogctlModSpec());
    }

    @Test
    public void canSpeficyOnlySome() {
        String wanted = "fatal=off,error=off,warning=on,info=off,event=off,config=off,debug=on,spam=off";
        var l = new LevelsModSpec();
        l.setLevels("warning debug");
        assertEquals(wanted, l.toLogctlModSpec());
        l = new LevelsModSpec();
        l.setLevels("warning,debug");
        assertEquals(wanted, l.toLogctlModSpec());
        l = new LevelsModSpec();
        l.setLevels("warning, debug");
        assertEquals(wanted, l.toLogctlModSpec());
    }

    @Test
    public void canSpeficyAllMinusSome() {
        String wanted ="fatal=on,error=on,warning=on,info=off,event=on,config=on,debug=on,spam=off";
        var l = new LevelsModSpec();
        l.setLevels("all -info -spam");
        assertEquals(wanted, l.toLogctlModSpec());
        l = new LevelsModSpec();
        l.setLevels("all,-info,-spam");
        assertEquals(wanted, l.toLogctlModSpec());
        l = new LevelsModSpec();
        l.setLevels("all, -info, -spam");
        assertEquals(wanted, l.toLogctlModSpec());
    }

}