StructuredLoggingJsonProperties Class — spring-boot Architecture
Architecture documentation for the StructuredLoggingJsonProperties class in StructuredLoggingJsonProperties.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java lines 58–188
record StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude, Map<String, String> rename,
Map<String, String> add, @Nullable StackTrace stackTrace, @Nullable Context context,
Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizer) {
StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude, Map<String, String> rename,
Map<String, String> add, @Nullable StackTrace stackTrace, @Nullable Context context,
@Nullable Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizer) {
this.include = include;
this.exclude = exclude;
this.rename = rename;
this.add = add;
this.stackTrace = stackTrace;
this.context = context;
this.customizer = (customizer != null) ? customizer : Collections.emptySet();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
Collection<StructuredLoggingJsonMembersCustomizer<Object>> customizers(Instantiator<?> instantiator) {
return (List) customizer().stream().map(instantiator::instantiateType).toList();
}
static @Nullable StructuredLoggingJsonProperties get(Environment environment) {
return Binder.get(environment)
.bind("logging.structured.json", StructuredLoggingJsonProperties.class)
.orElse(null);
}
/**
* Properties to influence stack trace printing.
*
* @param printer the name of the printer to use. Can be {@code null},
* {@code "standard"}, {@code "logging-system"}, or the fully-qualified class name of
* a {@link StackTracePrinter} implementation. A {@code null} value will be treated as
* {@code "standard"} when any other property is set, otherwise it will be treated as
* {@code "logging-system"}. {@link StackTracePrinter} implementations may optionally
* inject a {@link StandardStackTracePrinter} instance into their constructor which
* will be configured from the properties.
* @param root the root ordering (root first or root last)
* @param maxLength the maximum length to print
* @param maxThrowableDepth the maximum throwable depth to print
* @param includeCommonFrames whether common frames should be included
* @param includeHashes whether stack trace hashes should be included
*/
record StackTrace(@Nullable String printer, @Nullable Root root, @Nullable Integer maxLength,
@Nullable Integer maxThrowableDepth, @Nullable Boolean includeCommonFrames,
@Nullable Boolean includeHashes) {
@Nullable StackTracePrinter createPrinter() {
String name = sanitizePrinter();
if ("loggingsystem".equals(name) || (name.isEmpty() && !hasAnyOtherProperty())) {
return null;
}
StandardStackTracePrinter standardPrinter = createStandardPrinter();
if ("standard".equals(name) || name.isEmpty()) {
return standardPrinter;
}
Assert.state(printer() != null, "'printer' must not be null");
return (StackTracePrinter) new Instantiator<>(StackTracePrinter.class,
(parameters) -> parameters.add(StandardStackTracePrinter.class, standardPrinter))
.instantiate(printer());
}
boolean hasCustomPrinter() {
String name = sanitizePrinter();
if (name.isEmpty()) {
return false;
}
return !("loggingsystem".equals(name) || "standard".equals(name));
}
private String sanitizePrinter() {
return Objects.toString(printer(), "").toLowerCase(Locale.ROOT).replace("-", "");
}
private boolean hasAnyOtherProperty() {
return Stream.of(root(), maxLength(), maxThrowableDepth(), includeCommonFrames(), includeHashes())
.anyMatch(Objects::nonNull);
}
private StandardStackTracePrinter createStandardPrinter() {
StandardStackTracePrinter printer = (root() == Root.FIRST) ? StandardStackTracePrinter.rootFirst()
: StandardStackTracePrinter.rootLast();
PropertyMapper map = PropertyMapper.get();
printer = map.from(this::maxLength).to(printer, StandardStackTracePrinter::withMaximumLength);
printer = map.from(this::maxThrowableDepth)
.to(printer, StandardStackTracePrinter::withMaximumThrowableDepth);
printer = map.from(this::includeCommonFrames)
.to(printer, apply(StandardStackTracePrinter::withCommonFrames));
printer = map.from(this::includeHashes).to(printer, apply(StandardStackTracePrinter::withHashes));
return printer;
}
private BiFunction<StandardStackTracePrinter, Boolean, StandardStackTracePrinter> apply(
UnaryOperator<StandardStackTracePrinter> action) {
return (printer, value) -> (!value) ? printer : action.apply(printer);
}
/**
* Root ordering.
*/
enum Root {
LAST, FIRST
}
}
/**
* Properties that influence context values (usually elements propagated from the
* logging MDC).
*
* @param include if context elements should be included
* @param prefix the prefix to use for context elements
* @since 3.5.0
*/
record Context(@DefaultValue("true") boolean include, @Nullable String prefix) {
}
static class StructuredLoggingJsonPropertiesRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
BindableRuntimeHintsRegistrar.forTypes(StructuredLoggingJsonProperties.class)
.registerHints(hints, classLoader);
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free