调用CLI命令获取指定游标(Cursor)位置的日志数据。该命令迭代式获取日志数据并返回输出结果,适用于获取大量日志数据的场景。
请求语法
aliyunlog log pull_logs --project_name=<value> --logstore_name=<value> --shard_id=<value> --cursor=<value> [--count=<value>] [--end_cursor=<value>] [--compress=<value>] [--access-id=<value>] [--access-key=<value>] [--sts-token=<value>] [--region-endpoint=<value>] [--client-name=<value>] [--jmes-filter=<value>] [--format-output=<value>] [--decode-output=<value>]
请求参数
该命令的必选和特有参数描述如下。
参数名称 | 数值类型 | 是否必选 | 示例值 | 描述 |
--project_name | String | 是 | aliyun-test-project | Project名称。 |
--logstore_name | String | 是 | logstore-a | Logstore名称。 |
--shard_id | Integer | 是 | 0 | Shard ID。 |
--cursor | String | 是 | MTYxNDc1MDAyNzM3MzIwNTcxNA== | 开始游标,表示从什么位置开始读取数据,相当于起点。 |
--count | Integer | 否 | 2 | 获取日志数量。 |
--end_cursor | String | 否 | MTYxNDc1MDAyNzM3MzIwNTcxNg== | 结束游标,相当于结束点。 |
--compress | Boolean | 否 | true | 是否压缩返回日志数据。
|
关于该命令的全局参数,请参见全局参数。
示例
请求示例
使用默认账号查询游标开始的2条日志。命令示例如下:
aliyunlog log pull_logs --project_name="aliyun-test-project" --logstore_name="logstroe-a" --shard_id=0 --cursor="MTYxNDc1MDAyNzM3MzIwNTcxNA==" --count="2"
返回示例
{ "count": 2, "logs": [ { "__source__": "203.0.113.10", "__tag__:__hostname__": "iZ3s******Z", "__tag__:__pack_id__": "81C4812927C6B529-15DA", "__tag__:__receive_time__": "1619597641", "__time__": 1619597638, "__topic__": "", "activity_id": "", "computer_name": "iZ3stckpfjj7wvZ", "event_id": "7036", "kernel_time": "0", "keywords": "[Classic]", "level": "Information", "log_name": "System", "message": "The Network Setup Service service entered the stopped state.", "message_error": "[]", "opcode": "", "process_id": "544", "processor_id": "0", "processor_time": "0", "provider_guid": "{555908d1-a6d7-4695-8e1e-26931d2012f4}", "record_number": "8623", "related_activity_id": "", "session_id": "0", "source_name": "Service Control Manager", "task": "", "thread_id": "3176", "type": "wineventlog", "user_data": "{\"xml_name\":\"\"}", "user_time": "0", "version": "0" }, { "__source__": "203.0.113.10", "__tag__:__hostname__": "iZ3******vZ", "__tag__:__pack_id__": "81C4812927C6B529-15DB", "__tag__:__receive_time__": "1619598347", "__time__": 1619598344, "__topic__": "", "activity_id": "", "computer_name": "iZ3stckpfjj7wvZ", "event_id": "7036", "kernel_time": "0", "keywords": "[Classic]", "level": "Information", "log_name": "System", "message": "The Windows Update service entered the running state.", "message_error": "[]", "opcode": "", "process_id": "544", "processor_id": "0", "processor_time": "0", "provider_guid": "{555908d1-a6d7-4695-8e1e-26931d2012f4}", "record_number": "8624", "related_activity_id": "", "session_id": "0", "source_name": "Service Control Manager", "task": "", "thread_id": "6868", "type": "wineventlog", "user_data": "{\"xml_name\":\"\"}", "user_time": "0", "version": "0" } ], "next_cursor": "MTYxNDc1MDAyNzM3MzIwNTcxNg==" }
错误码
如果返回报错信息,请参见具体接口的错误码处理。
HttpStatusCode | ErrorCode | ErrorMessage | 错误码描述 |
404 | LogStoreNotExist | Logstore does not exist. | Logstore不存在。 |
400 | ParameterInvalid | Invalid cursor. | 游标参数无效。 |
400 | ParameterInvalid | ParameterCount should be in [0-1000]. | count参数取值范围应该为[0-1000]。 |
400 | ShardNotExist | Shard does not exist. | Shard不存在。 |
400 | InternalServerError | Specified Server Error Message. | 内部服务调用错误。 |
更多信息,请参见通用错误码。