?
本文檔使用 php中文網(wǎng)手冊(cè) 發(fā)布
大gelf
日志驅(qū)動(dòng)程序是一種方便的格式,可以被許多工具理解,例如灰日志,,,洛格斯塔什,和流d許多工具都使用這種格式。
在GELF中,每條日志消息都是具有以下字段的塊:
版本
主機(jī)%28誰(shuí)首先發(fā)送消息?
時(shí)間戳
消息的簡(jiǎn)短和長(zhǎng)篇版本
配置自己的任何自定義字段
使用gelf
驅(qū)動(dòng)程序作為默認(rèn)日志記錄驅(qū)動(dòng)程序,設(shè)置log-driver
和log-opt
控件中的適當(dāng)值的鍵。daemon.json
文件,該文件位于/etc/docker/
在linux主機(jī)上或C:\ProgramData\docker\config\daemon.json
在WindowsServer上。有關(guān)配置Docker的更多信息,請(qǐng)使用daemon.json
,見(jiàn)daemon.json...
下面的示例將日志驅(qū)動(dòng)程序設(shè)置為gelf
并設(shè)置gelf-address
選擇。
{ "log-driver": "gelf", "log-opts": { "gelf-address": "udp://1.2.3.4:12201" }}
重新啟動(dòng)Docker以使更改生效。
使用gelf
作為新容器的默認(rèn)日志記錄驅(qū)動(dòng)程序,傳遞--log-driver
和--log-opt
Docker守護(hù)進(jìn)程的選項(xiàng):
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" }}
屬性設(shè)置特定容器的日志驅(qū)動(dòng)程序。--log-driver
使用時(shí)標(biāo)志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ū)動(dòng)程序支持以下選項(xiàng):
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). |
此示例將容器配置為使用運(yùn)行在192.168.0.42
港口12201
...
$ docker run -dit \ --log-driver=gelf \ --log-opt gelf-address=udp://192.168.0.42:12201 \ alpine sh