aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/LogFrameworksIntegrationTest.java
blob: 289510f42a543c66bfe9e81e154347d317b6f28d (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;

import com.yahoo.io.IOUtils;
import com.yahoo.jdisc.test.TestDriver;
import com.yahoo.log.LogSetup;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.util.List;

import static org.junit.Assert.assertTrue;


/**
 * @author Simon Thoresen Hult
 * @author gjoranv
 */
public class LogFrameworksIntegrationTest {
    private static final String VESPA_LOG_TARGET = "vespa.log.target";

    @Rule
    public TemporaryFolder tempFolder = new TemporaryFolder();

    @Test
    public void requireThatAllSupportedLogFrameworksAreConfigured() throws Exception {
        File logFile = tempFolder.newFile();
        try {
            System.setProperty(VESPA_LOG_TARGET, "file:" + logFile.getAbsolutePath());
            TestDriver driver = TestDriver.newApplicationBundleInstance("app-h-log.jar", false);

            List<String> logLines = IOUtils.getLines(logFile.getAbsolutePath());
            assertLogFileContains("[jdk14] hello world", logLines);
            assertLogFileContains("[slf4j] hello world", logLines);
            assertLogFileContains("[log4j] hello world", logLines);
            assertLogFileContains("[jcl] hello world", logLines);

            assertTrue(driver.close());
        } finally {
            System.clearProperty(VESPA_LOG_TARGET);
            // Triggers a warning that can be ignored. Necessary to reset the log target for later tests.
            LogSetup.initVespaLogging("jdisc_core_test");
        }
    }

    private static void assertLogFileContains(String expected, List<String> logLines) {
        for (var line : logLines) {
            if (line.contains(expected)) return;
        }
        Assert.fail("Log did not contain : " + expected);
    }

}