Reputation: 1031
I can see in Docker documentation: https://docs.docker.com/config/containers/logging/gelf/
In GELF, every log message is a dict with the following fields: ... any custom fields you configure yourself
Does it mean that this driver support custom fields?
I'd like to add custom field environment to each GELF message. How can I do that?
Upvotes: 9
Views: 1536
Reputation: 851
The documentation is indeed not very clear about that, but as explained here there's a way to add extra fields to your GELF message, that worked for me :
You need to provide the name of the extra fields you want to add through the --log-opt env=...
option, and then provide the fields values through your docker env, like so :
docker run --log-driver gelf --log-opt env=mycustomfield --log-opt gelf-address=udp://<your-domain>:12201 --env mycustomfield=mycustomvalue alpine echo hello world
Your resulting log message will contain the extra field "mycustomfield": "mycustomvalue"
.
Upvotes: 3
Reputation: 1469
Are you sending GELF messages into Graylog within your Docker container? If so, the Graylog GELF format does support custom fields. To supply a custom field, just add an underscore before the field name as shown here. As long as you also supply the required fields (see doc reference below), then the message will be parsed successfully.
See the GELF section in the Graylog docs for more information.
Upvotes: 0