org.catools.common.logger.converters.CBaseExecutionStatisticConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common.testng Show documentation
Show all versions of common.testng Show documentation
The common TestNG extensions
The newest version!
package org.catools.common.logger.converters;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import org.catools.common.utils.CStringUtil;
import java.util.function.Supplier;
public abstract class CBaseExecutionStatisticConverter extends LogEventPatternConverter {
private final Supplier supplier;
private final String stringFormat;
protected CBaseExecutionStatisticConverter(
final String name,
final String style,
final String stringFormat,
final Supplier supplier) {
super(name, style);
this.stringFormat = CStringUtil.defaultIfBlank(stringFormat, "%d");
this.supplier = supplier;
}
public static String validateAndGetOption(final String[] options) {
assert options.length < 2;
return options == null || options.length == 0 ? null : options[0];
}
@Override
public void format(LogEvent event, StringBuilder toAppendTo) {
toAppendTo.append(String.format(stringFormat, supplier.get()));
}
}