> For the complete documentation index, see [llms.txt](https://bernardo.gitbook.io/development-docs-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bernardo.gitbook.io/development-docs-java/logging-in-java/log4j/mapped-diagnostic-context.md).

# Mapped Diagnostic Context

The MDC allows using custom variables in the log:

```
%-5p | %X{principal}
```

In this case the "principal" variable is loaded through the MDC, as the "X" command tells.

This requires that same variable to be registered:

```java
MDC.put("principal", context.getAuthentication().getName());
```
