當您通過阿里雲CLI訪問API時,可以開啟日誌輸出功能以列印請求日誌。日誌可協助您分析請求及響應內容是否正確。
OSS命令的日誌功能使用請參考:OSS命令日誌功能
配置環境變數
在終端中,可以通過設定環境變數DEBUG=sdk
來開啟日誌功能。
開啟日誌功能後,以如下命令為例:
aliyun ecs DescribeRegions
輸出樣本:
# omitted output > POST /?AccessKeyId=AccessKeyId&Action=DescribeRegions&Format=JSON&RegionId=cn-hangzhou&Signature=u9lPKI5Nyw0dIKV5ytJAx6aOTJ0%3D&SignatureMethod=HMAC-SHA1&SignatureNonce=29f426485b2720f6ae0575c900590e28&SignatureType=&SignatureVersion=1.0&Timestamp=2020-05-18T09%3A52%3A42Z&Version=2014-05-26 HTTP/1.1 > Host: ecs-cn-hangzhou.aliyuncs.com > Content-Type: application/x-www-form-urlencoded > x-sdk-client: golang/1.0.0 > User-Agent: AlibabaCloud (darwin; amd64) Golang/1.13.9 Core/0.0.1 Aliyun-CLI/3.0.43 > x-sdk-invoke-type: common > Accept-Encoding: identity > x-sdk-core-version: 0.0.1 > Retry Times: 0. < HTTP/1.1 200 OK < Connection: keep-alive < Access-Control-Allow-Origin: * < Content-Length: 2238 < Vary: Accept-Encoding < Access-Control-Allow-Methods: POST, GET, OPTIONS < Access-Control-Allow-Headers: X-Requested-With, X-Sequence, _aop_secret, _aop_signature < Access-Control-Max-Age: 172800 < Date: Mon, 18 May 2020 09:52:43 GMT < Content-Type: application/json;charset=utf-8 < # omitted output
OSS命令日誌功能
OSS命令可以使用--loglevel
選項對日誌輸出層級進行定義。
可選值:
預設為空白,不進行輸出
info
:輸出提示資訊日誌debug
:輸出詳細日誌資訊
日誌將會輸出到檔案,檔案路徑將在終端顯示,例如以下命令:
aliyun oss ls --loglevel info
log file is /Users/user/Documents/ossutil.log
# omitted output