調用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. | 內部服務調用錯誤。 |
更多資訊,請參見通用錯誤碼。