kayx23 commented on code in PR #13272: URL: https://github.com/apache/apisix/pull/13272#discussion_r3143790183
########## docs/zh/latest/plugins/syslog.md: ########## @@ -27,118 +27,302 @@ description: API 网关 Apache APISIX syslog 插件可用于将日志推送到 S # --> -## 描述 +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/syslog" /> +</head> -`syslog` 插件可用于将日志推送到 Syslog 服务器。 +## 描述 -该插件还实现了将日志数据以 JSON 格式发送到 Syslog 服务的能力。 +`syslog` 插件将请求和响应日志以 JSON 对象批量推送到 syslog 服务器,并支持自定义日志格式。 ## 属性 -| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | -| ---------------- | ------- | ------ | ------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -| host | string | 是 | | | IP 地址或主机名。 | -| port | integer | 是 | | | 目标上游端口。 | -| name | string | 否 | "sys logger" | | 标识 logger 的唯一标识符。如果您使用 Prometheus 监视 APISIX 指标,名称将以 `apisix_batch_process_entries` 导出。 | -| timeout | integer | 否 | 3000 | [1, ...] | 上游发送数据超时(以毫秒为单位)。 | -| tls | boolean | 否 | false | | 当设置为 `true` 时执行 SSL 验证。 | -| flush_limit | integer | 否 | 4096 | [1, ...] | 如果缓冲的消息的大小加上当前消息的大小达到(> =)此限制(以字节为单位),则缓冲的日志消息将被写入日志服务器,默认为 4096(4KB)。 | -| drop_limit | integer | 否 | 1048576 | | 如果缓冲的消息的大小加上当前消息的大小大于此限制(以字节为单位),则由于缓冲区大小有限,当前的日志消息将被丢弃,默认为 1048576(1MB)。 | -| sock_type | string | 否 | "tcp" | ["tcp","udp"] | 用于传输层的 IP 协议类型。 | -| max_retry_count | integer | 否 | | [1, ...] | 连接到日志服务器失败或将日志消息发送到日志服务器失败后的最大重试次数。 | -| retry_delay | integer | 否 | | [0, ...] | 重试连接到日志服务器或重试向日志服务器发送日志消息之前的时间延迟(以毫秒为单位)。 | -| pool_size | integer | 否 | 5 | [5, ...] | `sock:keepalive` 使用的 Keepalive 池大小。 | -| log_format | object | 否 | | | 日志格式以 JSON 的键值对声明。值支持字符串和嵌套对象(最多五层,超出部分将被截断)。字符串中可通过在前面加上 `$` 来引用 [APISIX 变量](../apisix-variable.md) 或 [NGINX 内置变量](http://nginx.org/en/docs/varindex.html)。 | -| include_req_body | boolean | 否 | false | [false, true] | 当设置为 `true` 时包括请求体。 | -| include_req_body_expr | array | 否 | | | 当 `include_req_body` 属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true` 时,才会记录请求体。有关更多信息,请参阅 [lua-resty-expr](https://github.com/api7/lua-resty-expr) 。 | -| include_resp_body | boolean | 否 | false | [false, true] | 当设置为 `true` 时,包含响应体。 | -| include_resp_body_expr | array | 否 | | | 当 `include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true` 时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 | - -该插件支持使用批处理器来聚合并批量处理条目(日志/数据)。这样可以避免插件频繁地提交数据,默认情况下批处理器每 `5` 秒钟或队列中的数据达到 `1000` 条时提交数据,如需了解批处理器相关参数设置,请参考 [Batch-Processor](../batch-processor.md#配置)。 - -### 默认日志格式示例 - -```text -"<46>1 2024-01-06T02:30:59.145Z 127.0.0.1 apisix 82324 - - {\"response\":{\"status\":200,\"size\":141,\"headers\":{\"content-type\":\"text/plain\",\"server\":\"APISIX/3.7.0\",\"transfer-encoding\":\"chunked\",\"connection\":\"close\"}},\"route_id\":\"1\",\"server\":{\"hostname\":\"baiyundeMacBook-Pro.local\",\"version\":\"3.7.0\"},\"request\":{\"uri\":\"/opentracing\",\"url\":\"http://127.0.0.1:1984/opentracing\",\"querystring\":{},\"method\":\"GET\",\"size\":155,\"headers\":{\"content-type\":\"application/x-www-form-urlencoded\",\"host\":\"127.0.0.1:1984\",\"user-agent\":\"lua-resty-http/0.16.1 (Lua) ngx_lua/10025\"}},\"upstream\":\"127.0.0.1:1982\",\"apisix_latency\":100.99999809265,\"service_id\":\"\",\"upstream_latency\":1,\"start_time\":1704508259044,\"client_ip\":\"127.0.0.1\",\"latency\":101.99999809265}\n" -``` +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +|------------------------|---------|--------|--------------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| host | string | True | | | syslog 服务器的 IP 地址或主机名。 | +| port | integer | True | | | syslog 服务器的目标端口。 | +| timeout | integer | False | 3000 | 大于 0 | 向上游发送数据的超时时间(毫秒)。 | +| tls | boolean | False | false | | 若为 true,则验证 TLS。 | +| flush_limit | integer | False | 4096 | 大于 0 | 推送日志到 syslog 服务器前,缓冲区和当前消息的最大大小(字节,B)。 | +| drop_limit | integer | False | 1048576 | 大于 0 | 丢弃日志前,缓冲区和当前消息允许的最大大小(字节,B)。 | +| sock_type | string | False | `tcp` | `tcp` 或 `udp` | 使用的传输层协议。 | +| pool_size | integer | False | 5 | 大于等于 5 | `sock:keepalive` 使用的连接池大小。 | +| log_format | object | False | | | 以 JSON 键值对形式声明的自定义日志格式,值可以引用 [NGINX 变量](https://nginx.org/en/docs/http/ngx_http_core_module.html)。也可以通过[插件元数据](../terminology/plugin-metadata.md)在全局范围内配置日志格式,将应用于所有 `syslog` 插件实例。如果插件实例的日志格式与插件元数据的日志格式不同,插件实例的日志格式优先生效。 | +| include_req_body | boolean | False | false | | 若为 true,则在日志中包含请求体。注意:若请求体太大而无法保存在内存中,由于 NGINX 的限制,将无法记录。 | +| include_req_body_expr | array | False | | | [lua-resty-expr](https://github.com/api7/lua-resty-expr) 表达式数组。当 `include_req_body` 为 true 时使用,仅当此处表达式求值为 true 时才记录请求体。 | +| include_resp_body | boolean | False | false | | 若为 true,则在日志中包含响应体。 | +| include_resp_body_expr | array | False | | | [lua-resty-expr](https://github.com/api7/lua-resty-expr) 表达式数组。当 `include_resp_body` 为 true 时使用,仅当此处表达式求值为 true 时才记录响应体。 | +| max_req_body_bytes | integer | False | 524288 | 大于等于 1 | 日志中记录的最大请求体字节数。超出该值的请求体将被截断。在 APISIX 3.16.0 版本中可用。 | +| max_resp_body_bytes | integer | False | 524288 | 大于等于 1 | 日志中记录的最大响应体字节数。超出该值的响应体将被截断。在 APISIX 3.16.0 版本中可用。 | +| name | string | False | `sys logger` | | 批处理器中插件的唯一标识符。若使用 Prometheus 监控 APISIX 指标,该名称将以 `apisix_batch_process_entries` 导出。 | +| batch_max_size | integer | False | 1000 | 大于 0 | 每批次允许的最大日志条目数。达到该值后,批次将被发送至日志服务。设置为 1 表示立即处理。 | +| inactive_timeout | integer | False | 5 | 大于 0 | 在将批次发送至日志服务前等待新日志的最长时间(秒)。该值应小于 `buffer_duration`。 | +| buffer_duration | integer | False | 60 | 大于 0 | 发送批次前允许最早条目存在的最长时间(秒)。 | +| retry_delay | integer | False | 1 | 大于等于 0 | 批次发送失败后重试的时间间隔(秒)。 | +| max_retry_count | integer | False | 60 | 大于等于 0 | 丢弃日志条目前允许的最大重试次数。 | Review Comment: 此处 `max_retry_count` 的默认值记为 `60`,但 `apisix/utils/batch-processor.lua` 中实际默认值为 `0`。本 PR 中 http-logger、rocketmq-logger 均已修正为 `0`,请对 syslog 做相同修正。 ########## docs/en/latest/plugins/syslog.md: ########## @@ -26,58 +26,72 @@ description: This document contains information about the Apache APISIX syslog P # --> -## Description +<head> + <link rel="canonical" href="https://docs.api7.ai/hub/syslog" /> +</head> -The `syslog` Plugin is used to push logs to a Syslog server. +## Description -Logs can be set as JSON objects. +The `syslog` Plugin pushes request and response logs as JSON objects to syslog servers in batches and supports the customization of log formats. ## Attributes -| Name | Type | Required | Default | Valid values | Description | -|------------------|---------|----------|--------------|---------------|--------------------------------------------------------------------------------------------------------------------------| -| host | string | True | | | IP address or the hostname of the Syslog server. | -| port | integer | True | | | Target port of the Syslog server. | -| name | string | False | "sys logger" | | Identifier for the server. If you use Prometheus to monitor APISIX metrics, the name is exported in `apisix_batch_process_entries`. | -| timeout | integer | False | 3000 | [1, ...] | Timeout in ms for the upstream to send data. | -| tls | boolean | False | false | | When set to `true` performs TLS verification. | -| flush_limit | integer | False | 4096 | [1, ...] | Maximum size of the buffer (KB) and the current message before it is flushed and written to the server. | -| drop_limit | integer | False | 1048576 | | Maximum size of the buffer (KB) and the current message before the current message is dropped because of the size limit. | -| sock_type | string | False | "tcp" | ["tcp", "udp] | Transport layer protocol to use. | -| pool_size | integer | False | 5 | [5, ...] | Keep-alive pool size used by `sock:keepalive`. | -| log_format | object | False | | | Log format declared as key-value pairs in JSON. Values support strings and nested objects (up to five levels deep; deeper fields are truncated). Within strings, [APISIX](../apisix-variable.md) or [NGINX](http://nginx.org/en/docs/varindex.html) variables can be referenced by prefixing with `$`. | -| include_req_body | boolean | False | false | [false, true] | When set to `true` includes the request body in the log. | -| include_req_body_expr | array | False | | | Filter for when the `include_req_body` attribute is set to `true`. Request body is only logged when the expression set here evaluates to `true`. See [lua-resty-expr](https://github.com/api7/lua-resty-expr) for more. | -| max_req_body_bytes | integer | False | 524288 | >=1 | Request bodies within this size will be logged, if the size exceeds the configured value it will be truncated before logging. | -| include_resp_body | boolean | False | false | [false, true] | When set to `true` includes the response body in the log. | -| include_resp_body_expr | array | False | | | When the `include_resp_body` attribute is set to `true`, use this to filter based on [lua-resty-expr](https://github.com/api7/lua-resty-expr). If present, only logs the response if the expression evaluates to `true`. | -| max_resp_body_bytes | integer | False | 524288 | >=1 | Response bodies within this size will be logged, if the size exceeds the configured value it will be truncated before logging. | +| Name | Type | Required | Default | Valid values | Description | +|------------------------|---------|----------|--------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| host | string | True | | | IP address or hostname of the syslog server. | +| port | integer | True | | | Target port of the syslog server. | +| timeout | integer | False | 3000 | greater than 0 | Timeout for the upstream to send data, in milliseconds. | +| tls | boolean | False | false | | If true, verify TLS. | +| flush_limit | integer | False | 4096 | greater than 0 | Maximum size of the buffer and the current message in bytes (B) before the logs are pushed to the syslog server. | +| drop_limit | integer | False | 1048576 | greater than 0 | Maximum size of the buffer and the current message allowed in bytes (B) before the logs are dropped. | +| sock_type | string | False | `tcp` | `tcp` or `udp` | Transport layer protocol to use. | +| pool_size | integer | False | 5 | greater than or equal to 5 | Keep-alive pool size used by `sock:keepalive`. | +| log_format | object | False | | | Custom log format using key-value pairs in JSON format. Values can reference [NGINX variables](https://nginx.org/en/docs/http/ngx_http_core_module.html). You can also configure log format on a global scale using the [plugin metadata](../terminology/plugin-metadata.md), which configures the log format for all `syslog` Plugin instances. If the log format configured on the individual Plugin instance differs from the log format configured on Plugin metadata, the log format configured on the individual Plugin instance takes precedence. | +| include_req_body | boolean | False | false | | If true, include the request body in the log. Note that if the request body is too big to be kept in the memory, it cannot be logged due to NGINX's limitations. | +| include_req_body_expr | array | False | | | An array of one or more conditions in the form of [lua-resty-expr](https://github.com/api7/lua-resty-expr) expressions. Used when `include_req_body` is true. Request body is only logged when the expressions configured here evaluate to true. | +| include_resp_body | boolean | False | false | | If true, include the response body in the log. | +| include_resp_body_expr | array | False | | | An array of one or more conditions in the form of [lua-resty-expr](https://github.com/api7/lua-resty-expr) expressions. Used when `include_resp_body` is true. Response body is only logged when the expressions configured here evaluate to true. | +| max_req_body_bytes | integer | False | 524288 | greater than or equal to 1 | Maximum request body size in bytes to include in the log. If the request body exceeds this value, it will be truncated. Available in APISIX from 3.16.0. | +| max_resp_body_bytes | integer | False | 524288 | greater than or equal to 1 | Maximum response body size in bytes to include in the log. If the response body exceeds this value, it will be truncated. Available in APISIX from 3.16.0. | +| name | string | False | `sys logger` | | Unique identifier of the Plugin for the batch processor. If you use Prometheus to monitor APISIX metrics, the name is exported in `apisix_batch_process_entries`. | +| batch_max_size | integer | False | 1000 | greater than 0 | The number of log entries allowed in one batch. Once reached, the batch will be sent to the logging service. Setting this parameter to 1 means immediate processing. | +| inactive_timeout | integer | False | 5 | greater than 0 | The maximum time in seconds to wait for new logs before sending the batch to the logging service. The value should be smaller than `buffer_duration`. | +| buffer_duration | integer | False | 60 | greater than 0 | The maximum time in seconds from the earliest entry allowed before sending the batch to the logging service. | +| retry_delay | integer | False | 1 | greater than or equal to 0 | The time interval in seconds to retry sending the batch to the logging service if the batch was not successfully sent. | +| max_retry_count | integer | False | 60 | greater than or equal to 0 | The maximum number of unsuccessful retries allowed before dropping the log entries. | Review Comment: The `max_retry_count` default is documented as `60` here, but the actual default from `apisix/utils/batch-processor.lua` is `0`. The other plugins in this PR (http-logger, rocketmq-logger) have already been corrected to `0` — please apply the same fix here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
