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

io.jstach.rainbowgum.json.encoder.GelfEncoderConfigurator Maven / Gradle / Ivy

The newest version!
package io.jstach.rainbowgum.json.encoder;

import io.jstach.rainbowgum.LogConfig;
import io.jstach.rainbowgum.LogEncoder;
import io.jstach.rainbowgum.LogEncoder.EncoderProvider;
import io.jstach.rainbowgum.LogProvider;
import io.jstach.rainbowgum.LogProviderRef;
import io.jstach.rainbowgum.spi.RainbowGumServiceProvider;
import io.jstach.rainbowgum.spi.RainbowGumServiceProvider.Configurator;
import io.jstach.svc.ServiceProvider;

/**
 * Adds GELF
 * JSON Encoder to encoder registry with {@value GelfEncoder#GELF_SCHEME} URI scheme.
 */
@ServiceProvider(RainbowGumServiceProvider.class)
public class GelfEncoderConfigurator implements Configurator {

	/**
	 * Default constructor for service loader.
	 */
	public GelfEncoderConfigurator() {
	}

	@Override
	public boolean configure(LogConfig config, Pass pass) {
		config.encoderRegistry().register(GelfEncoder.GELF_SCHEME, new GelfEncoderProvider());
		return true;
	}

	private static class GelfEncoderProvider implements EncoderProvider {

		@Override
		public LogProvider provide(LogProviderRef ref) {
			return (name, c) -> {
				var uri = ref.uri();
				GelfEncoderBuilder b = new GelfEncoderBuilder(name);
				String host = uri.getHost();
				if (host != null) {
					b.host(host);
				}
				b.fromProperties(c.properties(), ref);
				return b.build();
			};
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy