This example show how to automatically populate MDC values from the Path
expression of a JAX-RS service. In other words, a log definition file document
containing a key
keys
- id:
name: Document id
type: string
description: The internal id of the document
example: abc
and a REST service with a method
@GET
@Path("/{id}/hello")
@Logged(DocumentStoreMarker.class)
public String message(@PathParam("id") String id) {
logger.info("Say hello");
return "Hello " + id;
}
will automatically populate the MDC with the id
. An HTTP request to /123/hello
will result in log output.
{
"message" : "Say hello",
"document" : {
"id" : "123"
}
}
The path identifiers must match keys used in the log definiton. In addition, Date
types are not supported.