首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Graylog扩展格式(GELF)日志记录驱动程序(引擎) | Graylog Extended Format (GELF) logging driver (Engine)

gelf日志驱动程序是一种方便的格式,可以被许多工具理解,例如灰日志,,,洛格斯塔什,和流d许多工具都使用这种格式。

在GELF中,每条日志消息都是具有以下字段的块:

  • 版本
  • 主机%28谁首先发送消息?
  • 时间戳
  • 消息的简短和长篇版本
  • 配置自己的任何自定义字段

使用

使用gelf驱动程序作为默认日志记录驱动程序,设置log-driverlog-opt控件中的适当值的键。daemon.json文件,该文件位于/etc/docker/在linux主机上或C:\ProgramData\docker\config\daemon.json在WindowsServer上。有关配置Docker的更多信息,请使用daemon.json,见daemon.json...

下面的示例将日志驱动程序设置为gelf并设置gelf-address选择。

代码语言:javascript
复制
{
  "log-driver": "gelf",
  "log-opts": {
    "gelf-address": "udp://1.2.3.4:12201"
  }
}

重新启动Docker以使更改生效。

使用gelf作为新容器的默认日志记录驱动程序,传递--log-driver--log-optDocker守护进程的选项:

代码语言:javascript
复制
dockerd
  -–log-driver gelf –-log-opt gelf-address=udp://1.2.3.4:12201 \

要使配置永久化,可以在/etc/docker/daemon.json*

代码语言:javascript
复制
{
  "log-driver": "gelf",
  "log-opts":  {
    "gelf-address": "udp://1.2.3.4:12201"
  }
}

属性设置特定容器的日志驱动程序。--log-driver使用时标志docker createdocker run*

代码语言:javascript
复制
$ docker run \
      -–log-driver gelf –-log-opt gelf-address=udp://1.2.3.4:12201 \
      alpine echo hello world

GELF选项

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

代码语言:javascript
复制
$ docker run -dit \
             --log-driver=gelf \
             --log-opt gelf-address=udp://192.168.0.42:12201 \
             alpine sh

灰日志,,,GELF,,,测井,,,司机

扫码关注腾讯云开发者

领取腾讯云代金券