Log4j Docker Support
Log4j supports Docker by providing a Lookup to retrieve container information.
Accessing Docker
The Log4j Docker support requires access to the Docker REST interface. In practical terms this means the application either needs access to unix:///var/run/docker.sock through a volume mount (not recommended), bind Docker to another host/port or unix socket. or use a proxy application to provide access. The Log4j Spring Cloud sample application uses a socat proxy to access Docker.
Lookup Attributes
Log4j Docker provides access to the following container attributes:
- containerId - The full id assigned to the container.
- containerName - The name assigned to the container.
- imageId - The id assigned to the image.
- imageName - The name assigned to the image.
- shortContainerId - The first 12 characters of the container id.
- shortImageId - The first 12 characters of the image id.
Attributes may be accessed by adding
${docker:containerId}
to the configuration. Note that docker variables are only resolved once during logging initialization so they shouldn’t be referenced with more than one ‘$’ character.
Requirements
Log4j Docker requires Log4j Core, Log4j API and a minimum of Java 8. For more information, see Runtime Dependencies.