com.chavaillaz.jakarta.rs.LoggedField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaxrs-logging Show documentation
Show all versions of jaxrs-logging Show documentation
Library to log requests and responses of JAX-RS resources with MDC
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