Search in sources :

Example 1 with TRUE

use of org.neo4j.configuration.SettingValueParsers.TRUE in project neo4j by neo4j.

the class HttpStructuredLoggingIT method shouldLogRequestsInStructuredFormat.

@Test
public void shouldLogRequestsInStructuredFormat() throws Exception {
    var bootstrapper = new CommunityBootstrapper();
    HttpResponse<String> response;
    Path httpLogPath;
    try {
        bootstrapper.start(folder.homePath(), Map.of(HttpConnector.listen_address.name(), "localhost:0", ServerSettings.http_log_format.name(), FormattedLogFormat.JSON.name(), ServerSettings.http_logging_enabled.name(), TRUE, HttpConnector.enabled.name(), TRUE));
        var dependencyResolver = getDependencyResolver(bootstrapper.getDatabaseManagementService());
        var baseUri = dependencyResolver.resolveDependency(AbstractNeoWebServer.class).getBaseUri();
        var config = dependencyResolver.resolveDependency(Config.class);
        var request = HttpRequest.newBuilder().uri(baseUri).timeout(Duration.ofSeconds(10)).header("Accept", "application/json").header("User-Agent", HttpStructuredLoggingIT.class.getSimpleName()).GET().build();
        // Just ask the discovery api for a response we don't actually care of
        httpLogPath = config.get(ServerSettings.http_log_path);
        response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
    } finally {
        bootstrapper.stop();
        // Make sure the log manager flushes everything.
        LogManager.shutdown();
    }
    assertThat(response.statusCode()).isEqualTo(200);
    var httpLogLines = Files.readAllLines(httpLogPath).stream().map(s -> {
        try {
            return OBJECT_MAPPER.readValue(s, MAP_TYPE);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
    assertThat(httpLogLines).anyMatch(logEntry -> logEntry.getOrDefault("message", "").contains(HttpStructuredLoggingIT.class.getSimpleName()));
}
Also used : Path(java.nio.file.Path) ExclusiveWebContainerTestBase(org.neo4j.test.server.ExclusiveWebContainerTestBase) ServerSettings(org.neo4j.server.configuration.ServerSettings) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) HttpRequest(java.net.http.HttpRequest) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) HttpConnector(org.neo4j.configuration.connectors.HttpConnector) Duration(java.time.Duration) Map(java.util.Map) HttpClient(java.net.http.HttpClient) AbstractNeoWebServer(org.neo4j.server.AbstractNeoWebServer) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) DependencyResolver(org.neo4j.common.DependencyResolver) HttpResponse(java.net.http.HttpResponse) Files(java.nio.file.Files) FormattedLogFormat(org.neo4j.logging.FormattedLogFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) TRUE(org.neo4j.configuration.SettingValueParsers.TRUE) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) LogManager(org.apache.logging.log4j.LogManager) AbstractNeoWebServer(org.neo4j.server.AbstractNeoWebServer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) Test(org.junit.Test)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpClient (java.net.http.HttpClient)1 HttpRequest (java.net.http.HttpRequest)1 HttpResponse (java.net.http.HttpResponse)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.Test)1 DependencyResolver (org.neo4j.common.DependencyResolver)1 Config (org.neo4j.configuration.Config)1 DEFAULT_DATABASE_NAME (org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME)1 TRUE (org.neo4j.configuration.SettingValueParsers.TRUE)1 HttpConnector (org.neo4j.configuration.connectors.HttpConnector)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1