
org.elasticsearch.common.logging.JsonLogsStream Maven / Gradle / Ivy
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.common.logging;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* Returns a stream of json log lines.
* This is intended to be used for easy and readable assertions for logger tests
*/
public class JsonLogsStream {
private final XContentParser parser;
private final BufferedReader reader;
private final ObjectParser logLineParser;
private JsonLogsStream(BufferedReader reader, ObjectParser logLineParser) throws IOException {
this.reader = reader;
this.parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, reader);
this.logLineParser = logLineParser;
}
public static Stream from(BufferedReader reader, ObjectParser logLineParser) throws IOException {
return new JsonLogsStream(reader, logLineParser).stream();
}
public static Stream from(BufferedReader reader) throws IOException {
return new JsonLogsStream(reader, JsonLogLine.ECS_LOG_LINE).stream();
}
public static Stream from(Path path) throws IOException {
return from(Files.newBufferedReader(path));
}
public static Stream
© 2015 - 2025 Weber Informatics LLC | Privacy Policy