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()));
}
Aggregations