Home / Class/ JsonWriterStructuredLogFormatter Class — spring-boot Architecture

JsonWriterStructuredLogFormatter Class — spring-boot Architecture

Architecture documentation for the JsonWriterStructuredLogFormatter class in JsonWriterStructuredLogFormatter.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/main/java/org/springframework/boot/logging/structured/JsonWriterStructuredLogFormatter.java lines 36–81

public abstract class JsonWriterStructuredLogFormatter<E> implements StructuredLogFormatter<E> {

	private final JsonWriter<E> jsonWriter;

	/**
	 * Create a new {@link JsonWriterStructuredLogFormatter} instance with the given
	 * members.
	 * @param members a consumer, which should configure the members
	 * @param customizer an optional customizer to apply
	 */
	protected JsonWriterStructuredLogFormatter(Consumer<Members<E>> members,
			@Nullable StructuredLoggingJsonMembersCustomizer<?> customizer) {
		this(JsonWriter.of(customized(members, customizer)).withNewLineAtEnd());
	}

	private static <E> Consumer<Members<E>> customized(Consumer<Members<E>> members,
			@Nullable StructuredLoggingJsonMembersCustomizer<?> customizer) {
		return (customizer != null) ? members.andThen(customizeWith(customizer)) : members;
	}

	@SuppressWarnings("unchecked")
	private static <E> Consumer<Members<E>> customizeWith(StructuredLoggingJsonMembersCustomizer<?> customizer) {
		return (members) -> LambdaSafe.callback(StructuredLoggingJsonMembersCustomizer.class, customizer, members)
			.invoke((instance) -> instance.customize(members));
	}

	/**
	 * Create a new {@link JsonWriterStructuredLogFormatter} instance with the given
	 * {@link JsonWriter}.
	 * @param jsonWriter the {@link JsonWriter}
	 */
	protected JsonWriterStructuredLogFormatter(JsonWriter<E> jsonWriter) {
		this.jsonWriter = jsonWriter;
	}

	@Override
	public String format(E event) {
		return this.jsonWriter.writeToString(event);
	}

	@Override
	public byte[] formatAsBytes(E event, Charset charset) {
		return this.jsonWriter.write(event).toByteArray(charset);
	}

}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free