
org.broadinstitute.hellbender.utils.logging.OneShotLogger Maven / Gradle / Ivy
The newest version!
package org.broadinstitute.hellbender.utils.logging;
import com.google.common.annotations.VisibleForTesting;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.function.Supplier;
/**
* A logger wrapper class which only outputs the first warning provided to it
*/
public class OneShotLogger {
@VisibleForTesting
Logger logger;
private boolean hasWarned = false;
public OneShotLogger(final Class> clazz) {
logger = LogManager.getLogger(clazz);
}
public OneShotLogger(final Logger logger) {
this.logger = logger;
}
/*
* Will write a warning only once for an instance, otherwise it doesn't emit a message
*/
public void warn(String message) {
if (!hasWarned) {
logger.warn(message);
hasWarned=true;
}
}
public void warn(Supplier> msgSupplier) {
if (!hasWarned) {
logger.warn(msgSupplier);
hasWarned = true;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy