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?
The Graylog Extended Log Format (GELF) is a uniquely convenient log format created to deal with all the shortcomings of classic plain Syslog. This enterprise feature allows you to collect structured events from anywhere, and then compress and chunk them in the blink of an eye.
The gelf logging driver is a convenient format that is understood by a number of tools such as Graylog, Logstash, and Fluentd. Many tools use this format. In GELF, every log message is a dict with the following fields: version. host (who sent the message in the first place)
By default, no log-rotation is performed. As a result, log-files stored by the default json-file logging driver logging driver can cause a significant amount of disk space to be used for containers that generate much output, which can lead to disk space exhaustion.
You can run the command kubectl exec -it <container_name> bash and use the command line inside the container to change the environment variable . You can do it by running the command export LOG_LEVEL=debug or export LOG_LEVEL=error inside the container.
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"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With