Home / Class/ StackTrace Class — spring-boot Architecture

StackTrace Class — spring-boot Architecture

Architecture documentation for the StackTrace 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 101–164

	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

		}

	}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free