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

io.github.naviud.logtracker.actions.trackerproviders.TrackerIdFetcher Maven / Gradle / Ivy

Go to download

LogTracker is a logger module done for Play framework which prepends a unique UUID(tracker id) for the log messages that are generated for a particular request. Tracker id can be passed from a HTTP header or will be selected randomly when a request is initiated.

There is a newer version: 1.1.3
Show newest version
package io.github.naviud.logtracker.actions.trackerproviders;

import org.apache.commons.lang3.StringUtils;
import play.mvc.Http;

/**
 * Interface to fetch the tracker id from sources
 *
 */
public abstract class TrackerIdFetcher {

    private TrackerIdFetcher nextTrackerIdFetcher;

    /**
     * Method to set setNextProvider tracker id provider
     *
     * @param next Next tracker id provider to set
     */
    public void setNextProvider(TrackerIdFetcher next) {
        this.nextTrackerIdFetcher = next;
    }

    /**
     * Method to get the tracker id based on the availability
     *
     * @param ctx HTTP context
     * @return tracker id
     */
    public String get(Http.Context ctx) {
        String id = null;
        TrackerIdFetcher trackerIdFetcher = this;
        while (trackerIdFetcher != null) {
            id = trackerIdFetcher.fetch(ctx);
            if(StringUtils.isEmpty(id)) {
                trackerIdFetcher = nextTrackerIdFetcher;
            } else {
                break;
            }
        }
        return id;
    }

    /**
     * Method to fetch the tracker id
     *
     * @param ctx Http.Context
     * @return tracker id
     */
    abstract String fetch(Http.Context ctx);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy