Docker Gelf driver custom fields
Asked Answered
E

2

8

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?

Eureka answered 29/10, 2018 at 15:47 Comment(0)
W
2

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".

Westhead answered 29/5, 2020 at 13:11 Comment(2)
what a weird way, does it work on 2022?Attest
It still works for me !Westhead
D
0

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.

Additional GELF field

See the GELF section in the Graylog docs for more information.

Denson answered 14/11, 2018 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.