You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2022/08/03 01:29:59 UTC

[apisix] branch master updated: docs: refactor http-logger plugin doc (#7528)

This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new a2fdf08a4 docs: refactor http-logger plugin doc  (#7528)
a2fdf08a4 is described below

commit a2fdf08a4417397c3bd4e82bb1fe4e1788f4094e
Author: Fei Han <97...@users.noreply.github.com>
AuthorDate: Wed Aug 3 09:29:54 2022 +0800

    docs: refactor http-logger plugin doc  (#7528)
---
 docs/en/latest/plugins/http-logger.md |  18 ++++--
 docs/zh/latest/plugins/http-logger.md | 116 ++++++++++++++++++++--------------
 2 files changed, 79 insertions(+), 55 deletions(-)

diff --git a/docs/en/latest/plugins/http-logger.md b/docs/en/latest/plugins/http-logger.md
index 5128af235..f14748006 100644
--- a/docs/en/latest/plugins/http-logger.md
+++ b/docs/en/latest/plugins/http-logger.md
@@ -2,10 +2,10 @@
 title: http-logger
 keywords:
   - APISIX
+  - API 网关
   - Plugin
   - HTTP Logger
-  - http-logger
-description: This document contains information about the Apache APISIX http-logger Plugin.
+description: This document contains information about the Apache APISIX http-logger Plugin. Using this Plugin, you can push APISIX log data to HTTP or HTTPS servers.
 ---
 
 <!--
@@ -38,7 +38,7 @@ This will allow the ability to send log data requests as JSON objects to monitor
 | Name                   | Type    | Required | Default       | Valid values         | Description                                                                                                                                                                                                              |
 | ---------------------- | ------- | -------- | ------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
 | uri                    | string  | True     |               |                      | URI of the HTTP/HTTPS server.                                                                                                                                                                                            |
-| auth_header            | string  | False    |               |                      | Authorization headers if required.                                                                                                                                                                                       |
+| auth_header            | string  | False    | ""            |                      | Authorization headers if required.                                                                                                                                                                                       |
 | timeout                | integer | False    | 3             | [1,...]              | Time to keep the connection alive for after sending a request.                                                                                                                                                           |
 | name                   | string  | False    | "http logger" |                      | Unique identifier to identify the logger.                                                                                                                                                                                |
 | include_req_body       | boolean | False    | false         | [false, true]        | When set to `true` includes the request body in the log. If the request body is too big to be kept in the memory, it can't be logged due to Nginx's limitations.                                                         |
@@ -47,8 +47,12 @@ This will allow the ability to send log data requests as JSON objects to monitor
 | concat_method          | string  | False    | "json"        | ["json", "new_line"] | Sets how to concatenate logs. When set to `json`, uses `json.encode` for all pending logs and when set to `new_line`, also uses `json.encode` but uses the newline (`\n`) to concatenate lines.                          |
 | ssl_verify             | boolean | False    | false         | [false, true]        | When set to `true` verifies the SSL certificate.                                                                                                                                                                         |
 
+:::note
+
 This Plugin supports using batch processors to aggregate and process entries (logs/data) in a batch. This avoids the need for frequently submitting the data. The batch processor submits data every `5` seconds or when the data in the queue reaches `1000`. See [Batch Processor](../batch-processor.md#configuration) for more information or setting your custom configuration.
 
+:::
+
 ## Metadata
 
 You can also set the format of the logs by configuring the Plugin metadata. The following configurations are available:
@@ -66,7 +70,8 @@ Configuring the Plugin metadata is global in scope. This means that it will take
 The example below shows how you can configure through the Admin API:
 
 ```shell
-curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
 {
     "log_format": {
         "host": "$host",
@@ -88,7 +93,8 @@ With this configuration, your logs would be formatted as shown below:
 The example below shows how you can enable the Plugin on a specific Route:
 
 ```shell
-curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl http://127.0.0.1:9080/apisix/admin/routes/1 \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
 {
       "plugins": {
             "http-logger": {
@@ -117,7 +123,7 @@ curl -i http://127.0.0.1:9080/hello
 
 ## Disable Plugin
 
-To disable the `http-logger` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.
+To disable this Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.
 
 ```shell
 curl http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
diff --git a/docs/zh/latest/plugins/http-logger.md b/docs/zh/latest/plugins/http-logger.md
index 1cdad3c8b..ca874ef21 100644
--- a/docs/zh/latest/plugins/http-logger.md
+++ b/docs/zh/latest/plugins/http-logger.md
@@ -1,7 +1,15 @@
 ---
 title: http-logger
+keywords:
+  - APISIX
+  - API 网关
+  - 插件
+  - HTTP Logger
+  - 日志
+description: 本文介绍了 API 网关 Apache APISIX 的 http-logger 插件。使用该插件可以将 APISIX 的日志数据推送到 HTTP 或 HTTPS 服务器。
 ---
 
+
 <!--
 #
 # Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,32 +31,68 @@ title: http-logger
 
 ## 描述
 
-`http-logger` 是一个插件,可将 Log 数据请求推送到 HTTP / HTTPS 服务器。
-
-这将提供将 Log 数据请求作为 JSON 对象发送到监视工具和其他 HTTP 服务器的功能。
+`http-logger` 插件可以将 APISIX 的日志数据推送到 HTTP 或 HTTPS 服务器。该插件提供了将日志数据请求作为 JSON 对象发送到监控工具或者其他 HTTP 服务器的功能。
 
 ## 属性
 
+| 名称                   | 类型     | 必选项 | 默认值         | 有效值               | 描述                                             |
+| ---------------------- | ------- | ------ | ------------- | -------------------- | ------------------------------------------------ |
+| uri                    | string  | 是     |               |                      | HTTP 或 HTTPS 服务器的 URI。                   |
+| auth_header            | string  | 否     | ""            |                      | 授权 header(如果需要)。                                    |
+| timeout                | integer | 否     | 3             | [1,...]              | 发送请求后保持连接处于活动状态的时间。           |
+| name                   | string  | 否     | "http logger" |                      | 标识 logger 的唯一标识符。                     |
+| include_req_body       | boolean | 否     | false         | [false, true]        | 当设置为 `true` 时,将请求体包含在日志中。如果请求体太大而无法保存在内存中,由于 NGINX 的限制,无法记录。 |
+| include_resp_body      | boolean | 否     | false         | [false, true]        | 当设置为 `true` 时,包含响应体。                                                                                               |
+| include_resp_body_expr | array   | 否     |               |                      | 当 `include_resp_body` 属性设置为 `true` 时,使用该属性并基于 [lua-resty-expr](https://github.com/api7/lua-resty-expr) 进行过滤。 如果存在,则仅在表达式计算结果为 `true` 时记录响应。       |
+| concat_method          | string  | 否     | "json"        | ["json", "new_line"] | 枚举类型: **json**:对所有待发日志使用 `json.encode` 编码。**new_line**:对每一条待发日志单独使用 `json.encode` 编码并使用 `\n` 连接起来。 |
+| ssl_verify             | boolean | 否     | false          | [false, true]       | 当设置为 `true` 时验证证书。 |
+
+:::note 注意
+
+本插件支持使用批处理器来聚合并批量处理条目(日志和数据)。这样可以避免该插件频繁地提交数据。默认情况下每 `5` 秒钟或队列中的数据达到 `1000` 条时,批处理器会自动提交数据,如需了解更多信息或自定义配置,请参考 [Batch Processor](../batch-processor.md#配置)。
+
+:::
+
+## 插件元数据
+
 | 名称             | 类型    | 必选项 | 默认值        | 有效值  | 描述                                             |
 | ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ |
-| uri              | string  | 必须   |               |         | `HTTP/HTTPS` 服务器的 URI。                   |
-| auth_header      | string  | 可选   |               |         | 授权头部。                                    |
-| timeout          | integer | 可选   | 3             | [1,...] | 发送请求后保持连接活动的时间。                   |
-| name             | string  | 可选   | "http logger" |         | 标识 logger 的唯一标识符。                     |
-| include_req_body | boolean | 可选   | false         | [false, true] | 是否包括请求 body。false: 表示不包含请求的 body ; true: 表示包含请求的 body 。 |
-| include_resp_body| boolean | 可选   | false         | [false, true] | 是否包括响应体。包含响应体,当为`true`。 |
-| include_resp_body_expr | array  | 可选    |           |         | 是否采集响体,基于 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 该选项需要开启 `include_resp_body`|
-| concat_method    | string  | 可选   | "json"        | ["json", "new_line"] | 枚举类型: `json`、`new_line`。**json**: 对所有待发日志使用 `json.encode` 编码。**new_line**: 对每一条待发日志单独使用 `json.encode` 编码并使用 "\n" 连接起来。 |
-| ssl_verify       | boolean | optional    | false          | [false, true] | 是否验证证书。 |
+| log_format       | object  | 否    | {"host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr"} |         | 以 JSON 格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头。则表明获取 [APISIX 变量](../../../en/latest/apisix-variable.md) 或 [NGINX 内置变量](http://nginx.org/en/docs/varindex.html)。 |
+
+:::info 注意
+
+该设置全局生效。如果指定了 `log_format`,则所有绑定 `http-logger` 的路由或服务都将使用该日志格式。
+
+:::
+
+以下示例展示了如何通过 Admin API 配置插件元数据:
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "log_format": {
+        "host": "$host",
+        "@timestamp": "$time_iso8601",
+        "client_ip": "$remote_addr"
+    }
+}'
+```
 
-本插件支持使用批处理器来聚合并批量处理条目(日志/数据)。这样可以避免插件频繁地提交数据,默认设置情况下批处理器会每 `5` 秒钟或队列中的数据达到 `1000` 条时提交数据,如需了解或自定义批处理器相关参数设置,请参考 [Batch-Processor](../batch-processor.md#配置) 配置部分。
+配置完成后,你将在日志系统中看到如下类似日志:
+
+```shell
+{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
+{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
+```
 
-## 如何开启
+## 启用插件
 
-这是有关如何为特定路由启用 `http-logger` 插件的示例。你可以在 [mockbin](http://mockbin.org/bin/create) 生成一个模拟 HTTP 服务器来浏览生成的日志
+你可以通过如下命令在指定路由上启用 `http-logger` 插件:
 
 ```shell
-curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl http://127.0.0.1:9080/apisix/admin/routes/1 \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
 {
       "plugins": {
             "http-logger": {
@@ -65,49 +109,23 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
 }'
 ```
 
-## 测试插件
-
-> 成功:
-
-```shell
-$ curl -i http://127.0.0.1:9080/hello
-HTTP/1.1 200 OK
-...
-hello, world
-```
-
-## 插件元数据设置
-
-| 名称             | 类型    | 必选项 | 默认值        | 有效值  | 描述                                             |
-| ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ |
-| log_format       | object  | 可选   | {"host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr"} |         | 以 JSON 格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX 变量](../../../en/latest/apisix-variable.md) 或 [Nginx 内置变量](http://nginx.org/en/docs/varindex.html)。特别的,**该设置是全局生效的**,意味着指定 log_format 后,将对所有绑定 http-logger 的 Route 或 Service 生效。 |
-
-### 设置日志格式示例
+[mockbin](http://mockbin.org/bin/create) 服务器用于模拟 HTTP 服务器,以方便查看 APISIX 生成的日志。
 
-```shell
-curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
-{
-    "log_format": {
-        "host": "$host",
-        "@timestamp": "$time_iso8601",
-        "client_ip": "$remote_addr"
-    }
-}'
-```
+## 测试插件
 
-在日志收集处,将得到类似下面的日志:
+你可以通过以下命令向 APISIX 发出请求,访问日志将记录在你的 `mockbin` 服务器中:
 
 ```shell
-{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
-{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
+curl -i http://127.0.0.1:9080/hello
 ```
 
 ## 禁用插件
 
-在插件配置中删除相应的 json 配置以禁用 http-logger。APISIX 插件是热重载的,因此无需重新启动 APISIX:
+当你需要禁用该插件时,可以通过如下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务:
 
 ```shell
-$ curl http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+curl http://127.0.0.1:9080/apisix/admin/routes/1  \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
 {
     "methods": ["GET"],
     "uri": "/hello",