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

com.chavaillaz.jakarta.rs.LoggedField Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.chavaillaz.jakarta.rs;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

/**
 * List of context fields to be written in MDC.
 */
public enum LoggedField {

    REQUEST_ID("request-id"),
    REQUEST_METHOD("request-method"),
    REQUEST_URI("request-uri"),
    REQUEST_BODY("request-body"),
    RESPONSE_BODY("response-body"),
    RESPONSE_STATUS("response-status"),
    RESOURCE_CLASS("resource-class"),
    RESOURCE_METHOD("resource-method"),
    DURATION("duration");

    private final String defaultField;

    /**
     * Creates a new context field to be logged in MDC.
     *
     * @param defaultField The default MDC field name
     */
    LoggedField(String defaultField) {
        this.defaultField = defaultField;
    }

    /**
     * Gets a {@link Map} with the enumeration name as key and the default field name as value.
     *
     * @return The corresponding {@link Map}
     */
    public static Map getDefaultFields() {
        Map map = new HashMap<>();
        Stream.of(LoggedField.values()).forEach(entry -> map.put(entry.name(), entry.getDefaultField()));
        return map;
    }

    /**
     * Gets the default MDC field name to be used.
     *
     * @return The default name
     */
    public String getDefaultField() {
        return this.defaultField;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy