Docker GELF logging additional fields Docker GELF logging additional fields docker docker

Docker GELF logging additional fields


It does seem impossible in the current docker-compose version (1.8.0) to include the extra fields.

I ended up removing any logging configuration from the docker-compose file and instead integrate the GELF logging in the docker container's application. Since I am using JBoss AS 7, I have used the steps as described here: http://logging.paluch.biz/examples/jbossas7.html

To log the container id, I have added the following configuration:

<custom-handler name="GelfLogger" class="biz.paluch.logging.gelf.jboss7.JBoss7GelfLogHandler" module="biz.paluch.logging"><level name="INFO" /><properties>    <property name="host" value="udp:${GRAYLOG_HOST}" />    <property name="port" value="${GRAYLOG_PORT}" />    <property name="version" value="1.1" />    <property name="additionalFields" value="dockerContainer=${HOSTNAME}" />    <property name="includeFullMdc" value="true" /></properties>

Field dockerContainer is substituted by the HOSTNAME environment variable on the docker container and contains the containerId. The other placeholders are substituted by docker-compose environment variables.

By including the full MDC, I was able to put the username (and some other fields) as an additional GELF field. (For more information about MDC, see http://logback.qos.ch/manual/mdc.html)