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

de.otto.synapse.logging.ProgressLogger Maven / Gradle / Ivy

Go to download

A library used at otto.de to implement Spring Boot based event-sourcing microservices.

There is a newer version: 0.33.1
Show newest version
package de.otto.synapse.logging;

import org.slf4j.Logger;
import org.slf4j.Marker;

public class ProgressLogger {

    private long percentageCount = 0L;
    private long currentCount = 0L;

    private final Logger logger;
    private final long expectedCount;

    private final Marker marker;

    public ProgressLogger(final Logger logger,
                          final long expectedCount,
                          final Marker marker) {
        this.logger = logger;
        this.expectedCount = expectedCount;
        this.marker = marker;
    }

    public void incrementAndLog() {
        this.incrementAndLog(1);
    }

    public void incrementAndLog(int logStepSize) {
        currentCount++;
        long percentage = currentCount * 100 / expectedCount;
        if (percentage > percentageCount) {
            percentageCount++;
            if (percentageCount % logStepSize == 0) {
                logger.info(marker, "processed {}% of entries", percentage);
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy