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

cd.connect.logging.EnhancerServiceLoader Maven / Gradle / Ivy

Go to download

core functional logging for platform - loads services to enhance each log. we recommend async logger with log4j2.

There is a newer version: 2.2
Show newest version
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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy