当您通过阿里云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