Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Gelf driver custom fields

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?

like image 733
Piotr Kozlowski Avatar asked Oct 29 '18 15:10

Piotr Kozlowski


People also ask

What is GELF format?

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.

What is GELF driver?

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)

What happens if we do not specify a logging driver?

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.

How do I change the log level in a docker container?

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.


1 Answers

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

like image 81
benterris Avatar answered Oct 31 '22 16:10

benterris