# logging

该选项用于服务的日志配置。

```
logging:
  driver: syslog
  options:
    syslog-address: "tcp://192.168.0.42:123"
```

driver选项为服务的容器指定了一个日志驱动。等同于docker run --log-driver。

默认值是json-file。

```
driver: "json-file"
```

```
driver: "syslog"
```

```
driver: "none"
```

Note:

只有json-file和journald驱动可以让日志在docker-compose up和docker-compose logs时直接可用。使用任何其他的日志驱动都不会打印任何日志。

通过options键为logging驱动配置选项。options选项是键值对。下面是syslog选项示例：

```
driver: "syslog"
options:
  syslog-address: "tcp://192.168.0.42:123"
```

默认日志驱动有选项可以用来限制日志的存储数量。

```
options:
  max-size: "200k"
  max-file: "10"
```

上面的示例显示了最多可以存储200kb大小的日志，然后会轮询它们。单独保存日志的文件的大小可以通过max-file选项指定。一旦日志的增长超过了最大的限制，老的日志文件会被删除来允许新的日志文件被存储。

这里有一个限制日志存储的实例：

```
version: "3.9"
services:
  some-service:
    image: some-service
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
```

Note：

不同的日志驱动可以使用的options是不同的，这里用到的选项只能用于json-file日志驱动，无法用于其他日志驱动。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://camelgemonion.gitbook.io/docker/dockercompose.yaml-wen-jian-zhong-chang-yong-zhi-ling/untitled-12/untitled-15.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
