Home / Class/ GraylogExtendedLogFormatProperties Class — spring-boot Architecture

GraylogExtendedLogFormatProperties Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/main/java/org/springframework/boot/logging/structured/GraylogExtendedLogFormatProperties.java lines 38–111

public record GraylogExtendedLogFormatProperties(@Nullable String host, Service service) {

	static final GraylogExtendedLogFormatProperties NONE = new GraylogExtendedLogFormatProperties(null, null);

	public GraylogExtendedLogFormatProperties(@Nullable String host, @Nullable Service service) {
		this.host = host;
		this.service = (service != null) ? service : Service.NONE;
	}

	GraylogExtendedLogFormatProperties withDefaults(Environment environment) {
		String name = withFallbackProperty(environment, this.host, "spring.application.name");
		Service service = this.service.withDefaults(environment);
		return new GraylogExtendedLogFormatProperties(name, service);
	}

	static @Nullable String withFallbackProperty(Environment environment, @Nullable String value, String property) {
		return (!StringUtils.hasLength(value)) ? environment.getProperty(property) : value;
	}

	/**
	 * Add {@link JsonWriter} members for the service.
	 * @param members the members to add to
	 */
	@SuppressWarnings("NullAway") // Doesn't detect lambda with correct nullability
	public void jsonMembers(JsonWriter.Members<?> members) {
		members.add("host", this::host).whenHasLength();
		this.service.jsonMembers(members);
	}

	/**
	 * Return a new {@link GraylogExtendedLogFormatProperties} from bound from properties
	 * in the given {@link Environment}.
	 * @param environment the source environment
	 * @return a new {@link GraylogExtendedLogFormatProperties} instance
	 */
	public static GraylogExtendedLogFormatProperties get(Environment environment) {
		return Binder.get(environment)
			.bind("logging.structured.gelf", GraylogExtendedLogFormatProperties.class)
			.orElse(NONE)
			.withDefaults(environment);
	}

	/**
	 * Service details.
	 *
	 * @param version the version of the application
	 */
	public record Service(@Nullable String version) {

		static final Service NONE = new Service(null);

		Service withDefaults(Environment environment) {
			String version = withFallbackProperty(environment, this.version, "spring.application.version");
			return new Service(version);
		}

		@SuppressWarnings("NullAway") // Doesn't detect lambda with correct nullability
		void jsonMembers(JsonWriter.Members<?> members) {
			members.add("_service_version", this::version).whenHasLength();
		}

	}

	static class GraylogExtendedLogFormatPropertiesRuntimeHints implements RuntimeHintsRegistrar {

		@Override
		public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
			BindableRuntimeHintsRegistrar.forTypes(GraylogExtendedLogFormatProperties.class)
				.registerHints(hints, classLoader);
		}

	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free