![JAR search and dependency download from the Maven repository](/logo.png)
io.jstach.rainbowgum.pattern.format.PatternConfigBuilder 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.pattern.format.PatternConfig }.
*
* Properties retrieved from LogProperties
*
* Property Pattern
* Type
* Required
* Default
* Description
*
*
* {@value PROPERTY_zoneId }
* String (converted)
* false
* null
*
*
*
* {@value PROPERTY_lineSeparator }
* String
* false
* null
*
*
*
* {@value PROPERTY_ansiDisabled }
* Boolean
* false
* null
*
*
*
*/
public final class PatternConfigBuilder implements io.jstach.rainbowgum.LogBuilder {
/**
* The properties to be retrieved from config will have
* this prefix.
*/
static final String PROPERTY_PREFIX = "logging.pattern.config.{name}.";
/**
* {@value #PROPERTY_zoneId } = java.time.ZoneId
*/
static final String PROPERTY_zoneId = PROPERTY_PREFIX + "zoneId";
/**
* {@value #PROPERTY_lineSeparator } = java.lang.String
*/
static final String PROPERTY_lineSeparator = PROPERTY_PREFIX + "lineSeparator";
/**
* {@value #PROPERTY_ansiDisabled } = java.lang.Boolean
*/
static final String PROPERTY_ansiDisabled = PROPERTY_PREFIX + "ansiDisabled";
private final String propertyPrefix;
final Property property_zoneId;
final Property property_lineSeparator;
final Property property_ansiDisabled;
private final java.lang.String name;
private [email protected] ZoneId zoneId = null;
private [email protected] String lineSeparator = null;
private [email protected] Boolean ansiDisabled = null;
private [email protected] Function propertyFunction;
/**
* Create a builder for {@code io.jstach.rainbowgum.pattern.format.PatternConfig }.
* @param name will fill {name}
in logging.pattern.config.{name}.
.
*/
public PatternConfigBuilder(
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_zoneId = Property.builder()
.map(_v -> io.jstach.rainbowgum.pattern.format.PatternConfigurator.convertZoneId(_v))
.build(LogProperties.interpolateKey(PROPERTY_zoneId, prefixParameters));
property_lineSeparator = Property.builder()
.build(LogProperties.interpolateKey(PROPERTY_lineSeparator, prefixParameters));
property_ansiDisabled = Property.builder()
.ofBoolean()
.build(LogProperties.interpolateKey(PROPERTY_ansiDisabled, prefixParameters));
}
/**
* Sets propertyFunction.
*
* Default is null
.
* @param propertyFunction not configurable through properties
* @return this builder.
*/
public PatternConfigBuilder propertyFunction([email protected] Function propertyFunction) {
this.propertyFunction = propertyFunction;
return this;
}
/**
* Sets zoneId.
*
* Default is null
.
* @param zoneId {@value #PROPERTY_zoneId } = java.time.ZoneId
* @return this builder.
*/
public PatternConfigBuilder zoneId([email protected] ZoneId zoneId) {
this.zoneId = zoneId;
return this;
}
/**
* Sets lineSeparator.
*
* Default is null
.
* @param lineSeparator {@value #PROPERTY_lineSeparator } = java.lang.String
* @return this builder.
*/
public PatternConfigBuilder lineSeparator([email protected] String lineSeparator) {
this.lineSeparator = lineSeparator;
return this;
}
/**
* Sets ansiDisabled.
*
* Default is null
.
* @param ansiDisabled {@value #PROPERTY_ansiDisabled } = java.lang.Boolean
* @return this builder.
*/
public PatternConfigBuilder ansiDisabled([email protected] Boolean ansiDisabled) {
this.ansiDisabled = ansiDisabled;
return this;
}
/**
* Creates {@code io.jstach.rainbowgum.pattern.format.PatternConfig } from this builder.
* @return {@code io.jstach.rainbowgum.pattern.format.PatternConfig }.
*/
public io.jstach.rainbowgum.pattern.format.PatternConfig build() {
return io.jstach.rainbowgum.pattern.format.PatternConfigurator.provideFormatterConfig(
this.name
, this.zoneId
, this.lineSeparator
, this.ansiDisabled
, this.propertyFunction
);
}
@Override
public PatternConfigBuilder fromProperties(LogProperties properties) {
var __v = LogProperty.Validator.of(this.getClass());
var _zoneId = property_zoneId.get(properties).or(this.zoneId);
__v.addIfError(_zoneId);
var _lineSeparator = property_lineSeparator.get(properties).or(this.lineSeparator);
__v.addIfError(_lineSeparator);
var _ansiDisabled = property_ansiDisabled.get(properties).or(this.ansiDisabled);
__v.addIfError(_ansiDisabled);
__v.validate();
this.zoneId = _zoneId.valueOrNull();
this.lineSeparator = _lineSeparator.valueOrNull();
this.ansiDisabled = _ansiDisabled.valueOrNull();
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 _zoneId = this.zoneId;
if (_zoneId != null) {
consumer.accept(property_zoneId.key(), property_zoneId.propertyString(_zoneId));
}
var _lineSeparator = this.lineSeparator;
if (_lineSeparator != null) {
consumer.accept(property_lineSeparator.key(), property_lineSeparator.propertyString(_lineSeparator));
}
var _ansiDisabled = this.ansiDisabled;
if (_ansiDisabled != null) {
consumer.accept(property_ansiDisabled.key(), property_ansiDisabled.propertyString(_ansiDisabled));
}
}
/**
* The interpolated property prefix: {@value #PROPERTY_PREFIX}.
* @return resolved prefix which should end with a ".
".
*/
@Override
public String propertyPrefix() {
return this.propertyPrefix;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy