cd.connect.logging.EnhancerServiceLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connect-java-logging Show documentation
Show all versions of connect-java-logging Show documentation
core functional logging for platform - loads services to enhance each log.
we recommend async logger with log4j2.
package cd.connect.logging;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
/**
* @author Richard Vowles - https://plus.google.com/+RichardVowles
*/
public class EnhancerServiceLoader {
static List findJsonLogEnhancers() {
List enhancers = new ArrayList<>();
ServiceLoader serviceLoader = ServiceLoader.load(JsonLogEnhancer.class, Thread.currentThread().getContextClassLoader());
Iterator iterator = serviceLoader.iterator();
while (iterator.hasNext()) {
enhancers.add(iterator.next());
}
// jsonLogEnhancers.forEach(enhancers::add);
// in place sort by priority
enhancers.sort(new Comparator() {
@Override
public int compare(JsonLogEnhancer o1, JsonLogEnhancer o2) {
return Integer.compare(o1.getMapPriority(), o2.getMapPriority());
}
});
return enhancers;
}
}