©
本文档使用
php.cn手册 发布
大gelf
日志驱动程序是一种方便的格式,可以被许多工具理解,例如灰日志,,,洛格斯塔什,和流d许多工具都使用这种格式。
在GELF中,每条日志消息都是具有以下字段的块:
版本
主机%28谁首先发送消息?
时间戳
消息的简短和长篇版本
配置自己的任何自定义字段
使用gelf
驱动程序作为默认日志记录驱动程序,设置log-driver
和log-opt
控件中的适当值的键。daemon.json
文件,该文件位于/etc/docker/
在linux主机上或C:\ProgramData\docker\config\daemon.json
在WindowsServer上。有关配置Docker的更多信息,请使用daemon.json
,见daemon.json...
下面的示例将日志驱动程序设置为gelf
并设置gelf-address
选择。
{ "log-driver": "gelf", "log-opts": { "gelf-address": "udp://1.2.3.4:12201" }}
重新启动Docker以使更改生效。
使用gelf
作为新容器的默认日志记录驱动程序,传递--log-driver
和--log-opt
Docker守护进程的选项:
dockerd -–log-driver gelf –-log-opt gelf-address=udp://1.2.3.4:12201 \
要使配置永久化,可以在/etc/docker/daemon.json
*
{ "log-driver": "gelf", "log-opts": { "gelf-address": "udp://1.2.3.4:12201" }}
属性设置特定容器的日志驱动程序。--log-driver
使用时标志docker create
或docker run
*
$ docker run \ -–log-driver gelf –-log-opt gelf-address=udp://1.2.3.4:12201 \ alpine echo hello world
大gelf
日志驱动程序支持以下选项:
Option | Description | Example value |
---|---|---|
gelf-address | The address of the GELF server. udp is the only supported URI specifier and you must specify the port. | --log-opt gelf-address=udp://192.168.0.42:12201 |
gelf-compression-type | The type of compression the GELF driver uses to compress each log message. Allowed values are gzip, zlib and none. The default is gzip. | --log-opt gelf-compression-type=gzip |
gelf-compression-level | The level of compression when gzip or zlib is the gelf-compression-type. An integer in the range of -1 to 9 (BestCompression). Default value is 1 (BestSpeed). Higher levels provide more compression at lower speed. Either -1 or 0 disables compression. | --log-opt gelf-compression-level=2 |
tag | A string that is appended to the APP-NAME in the gelf message. By default, Docker uses the first 12 characters of the container ID to tag log messages. Refer to the log tag option documentation for customizing the log tag format. | --log-opt tag=mailer |
labels | Applies when starting the Docker daemon. A comma-separated list of logging-related labels this daemon will accept. Adds additional key on the extra fields, prefixed by an underscore (_). Used for advanced log tag options. | --log-opt labels=production_status,geo |
env | Applies when starting the Docker daemon. A comma-separated list of logging-related environment variables this daemon will accept. Adds additional key on the extra fields, prefixed by an underscore (_). Used for advanced log tag options. | --log-opt env=os,customer |
env-regex | Similar to and compatible with env. A regular expression to match logging-related environment variables. Used for advanced log tag options. | --log-opt env-regex=^(os | customer). |
此示例将容器配置为使用运行在192.168.0.42
港口12201
...
$ docker run -dit \ --log-driver=gelf \ --log-opt gelf-address=udp://192.168.0.42:12201 \ alpine sh