?
This document uses PHP Chinese website manual Release
大gelf
日志驅(qū)動程序是一種方便的格式,可以被許多工具理解,例如灰日志,,,洛格斯塔什,和流d許多工具都使用這種格式。
在GELF中,每條日志消息都是具有以下字段的塊:
版本
主機%28誰首先發(fā)送消息?
時間戳
消息的簡短和長篇版本
配置自己的任何自定義字段
使用gelf
驅(qū)動程序作為默認日志記錄驅(qū)動程序,設置log-driver
和log-opt
控件中的適當值的鍵。daemon.json
文件,該文件位于/etc/docker/
在linux主機上或C:\ProgramData\docker\config\daemon.json
在WindowsServer上。有關配置Docker的更多信息,請使用daemon.json
,見daemon.json...
下面的示例將日志驅(qū)動程序設置為gelf
并設置gelf-address
選擇。
{ "log-driver": "gelf", "log-opts": { "gelf-address": "udp://1.2.3.4:12201" }}
重新啟動Docker以使更改生效。
使用gelf
作為新容器的默認日志記錄驅(qū)動程序,傳遞--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" }}
屬性設置特定容器的日志驅(qū)動程序。--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
日志驅(qū)動程序支持以下選項:
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