Go için Alibaba Cloud SDK V1.0, her API çağrısının günlüklerini kaydetmek üzere bir SDK istemcisinde günlük kaydedici yapılandırmanıza olanak tanır.
Günlük kaydedici yapılandırması
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Örnek kod
import (
"os"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)
func main() {
config := sdk.NewConfig()
// Use the AccessKey ID and AccessKey secret of the Resource Access Management (RAM) user.
credential := credentials.NewAccessKeyCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
client, err := ecs.NewClientWithOptions("cn-hangzhou", config, credential)
if err != nil {
panic(err)
}
// Configure a logger in the SDK client. If you call this operation, the logging feature is enabled by default.
// level: the log level. Default value: info.
// channel: the data source of the log. Default value: AlibabaCloud.
// out: the output path of the log. The value is an object that can implement the io.writer interface.
// template: the log template. If you do not specify this parameter, the default value `{time} {channel}: "{method} {uri} HTTP/{version}" {code} {cost} {hostname}` is used.
defaultLoggerTemplate := `{time} {channel}: "{method} {uri} HTTP/{version}" {code} {cost} {host}`
client.SetLogger("info", "AlibabaCloud", os.Stdout, defaultLoggerTemplate)
request := ecs.CreateDescribeRegionsRequest()
client.DescribeRegions(request)
}
client.OpenLogger() // Enable the logging feature. If a logger does not exist in the SDK client, a default logger is created and configured.
client.SetTemplate(templete) // Configure the log template. If a logger does not exist in the SDK client, a default logger is created and configured.
Örnek günlük
[INFO]client.go:574: 2024-06-17 17:01:25 AlibabaCloud: "POST /?AccessKeyId=LTAI****************&Action=DescribeRegions&Format=JSON&RegionId=cn-hangzhou&Signature=bC773M84gqLqk93PO8vd%2Bmx%2FAmM%3D&SignatureMethod=HMAC-SHA1&SignatureNonce=9f8f6dd196e9663a343150a81de0986f&SignatureType=&SignatureVersion=1.0&Timestamp=2024-06-17T09%3A01%3A21Z&Version=2014-05-26 HTTP/1.1" 200 4.1605408s ecs-cn-hangzhou.aliyuncs.com
Şablonda yapılandırılabilecek değişkenler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|