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

io.github.naviud.logtracker.actions.trackerproviders.HeaderBasedTrackerIdFetcher 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 com.typesafe.config.Config;
import org.apache.commons.lang3.StringUtils;
import play.mvc.Http;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Implementation of TrackerIdFetcher for HTTP header based
 *
 */
@Singleton
public class HeaderBasedTrackerIdFetcher extends TrackerIdFetcher {

    private Config config;

    private static final String LOGTRACKER_TRACKER_PROVIDER_HEADER = "logtracker.tracker.header";

    @Inject
    public HeaderBasedTrackerIdFetcher(Config config) {
        this.config = config;
    }

    /**
     * Method to fetch the tracker id
     *
     * @return tracker id
     */
    @Override
    public String fetch(Http.Context ctx) {
        if
        (
                config.hasPath(LOGTRACKER_TRACKER_PROVIDER_HEADER) &&
                ctx.request().getHeaders().get(config.getString(LOGTRACKER_TRACKER_PROVIDER_HEADER)).isPresent()
        ) {
            return ctx.request()
                    .getHeaders()
                    .get(config.getString(LOGTRACKER_TRACKER_PROVIDER_HEADER))
                    .filter(StringUtils::isNotEmpty)
                    .get();
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy