GELF is a log format designed to address the shortcomings of traditional syslog formats. It was originally developed for the Graylog project but has since become a widely adopted standard in the logging ecosystem.
In our project, we use Docker’s built-in GELF logging driver to send container logs to Logstash. When we configure the Docker logging driver to use GELF:
logging:
driver: gelf
options:
gelf-address: "udp://${LOG_HOST}:12201"
tag: "service_name"
Each container sends its logs to Logstash in GELF format via UDP port 12201. The benefits include:
A typical GELF message includes:
{
"version": "1.1",
"host": "container_id",
"short_message": "Log message",
"full_message": "Extended log message (optional)",
"timestamp": 1618961053.654,
"level": 6,
"_container_name": "backend",
"_tag": "backend",
"_custom_field": "value"
}
_
) are custom fieldsOn macOS, special consideration is required when configuring GELF logging with Docker. Due to Docker’s virtualization layer on macOS:
localhost
inside a container refers to the container itself, not the host machinegelf-address
is set to udp://localhost:12201
, containers will try to send logs to themselves, not to the hostSolution: Update the gelf-address
in your docker-compose.yml to point to the Docker host using the special DNS name:
logging:
driver: gelf
options:
gelf-address: "udp://host.docker.internal:12201"
tag: "service_name"
The host.docker.internal
DNS name resolves to the host machine from within Docker containers on macOS, ensuring logs are correctly sent to Logstash running on the host.
This is why we chose GELF as the logging format for our Docker-based microservices architecture.