All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jstach.rainbowgum.pattern.format.PatternEncoderBuilder Maven / Gradle / Ivy

package io.jstach.rainbowgum.pattern.format;

import io.jstach.rainbowgum.LogProperties;
import io.jstach.rainbowgum.LogProperty;
import io.jstach.rainbowgum.LogProperty.Property;

/**
 * Builder to create {@link io.jstach.rainbowgum.LogProvider }.
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
Properties retrieved from LogProperties
Property PatternTypeRequiredDefaultDescription
{@value PROPERTY_pattern }Stringtruenull
*/ public final class PatternEncoderBuilder implements io.jstach.rainbowgum.LogBuilder> { /** * The properties to be retrieved from config will have * this prefix. */ static final String PROPERTY_PREFIX = "logging.encoder.{name}."; /** * {@value #PROPERTY_pattern } = java.lang.String */ static final String PROPERTY_pattern = PROPERTY_PREFIX + "pattern"; private final String propertyPrefix; final Property property_pattern; private final java.lang.String name; private [email protected] String pattern = null; private io.jstach.rainbowgum.pattern.format.@org.eclipse.jdt.annotation.Nullable PatternCompiler patternCompiler; /** * Create a builder for {@code io.jstach.rainbowgum.LogProvider }. * @param name will fill {name} in logging.encoder.{name}.. */ public PatternEncoderBuilder( java.lang.String name ) { java.util.Map prefixParameters = java.util.Map.of( "name", name ); this.propertyPrefix = LogProperties.interpolateKey(PROPERTY_PREFIX, prefixParameters); this.name = name; property_pattern = Property.builder() .build(LogProperties.interpolateKey(PROPERTY_pattern, prefixParameters)); } /** * Sets patternCompiler. * * Default is null. * @param patternCompiler not configurable through properties * @return this builder. */ public PatternEncoderBuilder patternCompiler(io.jstach.rainbowgum.pattern.format.@org.eclipse.jdt.annotation.Nullable PatternCompiler patternCompiler) { this.patternCompiler = patternCompiler; return this; } /** * Sets required pattern. * * Default is null. * @param pattern {@value #PROPERTY_pattern } = java.lang.String * @return this builder. */ public PatternEncoderBuilder pattern(java.lang.String pattern) { this.pattern = pattern; return this; } /** * Creates {@code io.jstach.rainbowgum.LogProvider } from this builder. * @return {@code io.jstach.rainbowgum.LogProvider }. */ public io.jstach.rainbowgum.LogProvider build() { return io.jstach.rainbowgum.pattern.format.PatternConfigurator.provideEncoder( this.name , property_pattern.require(this.pattern) , this.patternCompiler ); } @Override public PatternEncoderBuilder fromProperties(LogProperties properties) { var __v = LogProperty.Validator.of(this.getClass()); var _pattern = property_pattern.get(properties).or(this.pattern); __v.add(_pattern); __v.validate(); this.pattern = _pattern.value(); return this; } /** * Turns the builder into java.util.Properties like Map skipping values that are null. * @param consumer apply is called where first arg is key and second is value. */ public void toProperties(java.util.function.BiConsumer consumer) { var _pattern = this.pattern; if (_pattern != null) { consumer.accept(property_pattern.key(), property_pattern.propertyString(_pattern)); } } /** * The interpolated property prefix: {@value #PROPERTY_PREFIX}. * @return resolved prefix which should end with a ".". */ @Override public String propertyPrefix() { return this.propertyPrefix; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy