Package io.jstach.rainbowgum.pattern.format
@NonNullByDefault
package io.jstach.rainbowgum.pattern.format
Provides
Logback style
pattern formatters. The URI scheme of pattern encoders is
"pattern".
Register it like any other
Configuring
The supported builtin keywords are in the follow enum types:
Rainbow Gum does not currently support all of the builtin keywords that Logback does! But most of them are available.Adding a custom keyword
ExtendPatternKeywordProvider and
register a
PatternFormatterFactory.KeywordFactory (or
PatternFormatterFactory.CompositeFactory if
the keyword should accept a child pattern like %keyword(child)) with the
PatternRegistry. This example adds
%hostname, resolved once rather than on every event:
public class CustomPatternKeywordExample extends PatternKeywordProvider {
@Override
protected void register(PatternRegistry patternRegistry) {
// Adds "%hostname" as a usable keyword in patterns.
patternRegistry.keyword(PatternKey.of("hostname"), (config, node) -> HostnameFormatter.INSTANCE);
}
enum HostnameFormatter implements EventFormatter {
INSTANCE;
// Resolved once instead of on every event.
private static final String HOSTNAME = hostname();
private static String hostname() {
try {
return InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException e) {
return "unknown";
}
}
@Override
public void format(StringBuilder output, LogEvent event) {
output.append(HOSTNAME);
}
}
}
RainbowGumServiceProvider.
If your application is modularized:
provides io.jstach.rainbowgum.spi.RainbowGumServiceProvider with com.mycompany.CustomPatternKeywordExample;
Configuring PatternConfig
PatternConfig carries platform specific
settings (time zone, line separator, whether ANSI is disabled, the %r start
time) that keywords need. Prefer
property configuration (see the user guide's Pattern Module section) since it
is resolved per encoder name and needs no code. To instead set a programmatic default
used by every encoder that has no more specific property configuration, register a
PatternConfig - which is itself a
RainbowGumServiceProvider.Configurator - with
LogConfig.Builder.configurator(io.jstach.rainbowgum.spi.RainbowGumServiceProvider.Configurator):
LogConfig.Builder configure(LogConfig.Builder builder) {
return builder.configurator(PatternConfig.builder() //
.zoneId(ZoneOffset.UTC) //
.ansiDisabled(true) //
.build());
}
-
ClassDescriptionCompiles a pattern into a formatter.Builder for
PatternCompiler.Pattern Config needed for pattern keywords that is generally platform specific.Builder to createPatternConfig.Configures Logback style pattern encoders and offers provision with the URI scheme "pattern".Factory for pattern encoders.Builder to createLogProvider<LogEncoder>.Creates formatters from pattern keywords and are registered to aPatternRegistry.A composite formatter factory expects possible children.A keyword formatter factory expects keywords and option list.Pattern registry to register custom keywords.Built-in supported color pattern keys.Built-in supported pattern keys.Pattern keywords.Implement this interface along with the formatter for easier registration.Spring Boot patterns.