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

ltd.fdsa.starter.logger.influxdb.InfluxDbAppender Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package ltd.fdsa.starter.logger.influxdb;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import lombok.Data;
import lombok.var;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.Query;


@Data
public class InfluxDbAppender extends AppenderBase {

    private AppenderExecutor appenderExecutor;
    private InfluxDbSource source;

    @Override
    protected void append(ILoggingEvent iLoggingEvent) {
        appenderExecutor.append(iLoggingEvent);
    }

    @Override
    public void start() {
        initExecutor();
        super.start();

    }


    /**
     * This is an ad-hoc dependency injection mechanism. We don't want create all these classes every time a message is
     * logged. They will hang around for the lifetime of the appender.
     */
    private void initExecutor() {
        System.out.println(":: initExecutor :: begin: " + this.source.toString());

        InfluxDB influxdb = InfluxDBFactory.connect("http://" + source.getIp() + ":" + source.getPort(), source.getUser(), source.getPassword());
        String database = this.source.getDatabase();

        var q = influxdb.query(new Query("CREATE DATABASES " + database));
        influxdb.setDatabase(database);
        InfluxDbConverter converter = new InfluxDbConverter();
        appenderExecutor = new AppenderExecutor(converter, source, influxdb, getContext());
        System.out.println(":: initExecutor :: end");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy