百度智能云

All Product Document

          Log Service

          LogStore Operations

          Create logstores

          To create and name logstores, the following guidelines shall be met:

          • Logstore names must be unique per account and per region
          • The logstore name shall not be longer than 128 characters.
          • Only the following characters can permitted for logstore names: a-z, A-Z, 0-9, “_”, “-”, “.”
          • The logstore retention period can be set to a maximum of 3,650 days, indicating permanent retention. Unit: days.

          Use the following code to create a LogStore and specify its retention period.

          createLogStoreRequest := CreateLogStoreRequest{
              Project:      "default",
              LogStoreName: "test",
              Retention:    1,
          }
          err := BLS_CLIENT.CreateLogStoreV2(createLogStoreRequest)
          if err != nil {
            fmt.Println("Create logStore failed: ", err)
          } else {
            fmt.Println("Create logStore success.")
          }

          If you need to bind a tag when creating a LogStore, use the following code to set it up.

          tag := model.TagModel{
              TagKey:   "key",
              TagValue: "value",
          }
          tags := []model.TagModel{tag}
          createLogStoreRequest := CreateLogStoreRequest{
              Project:      DefaultProject,
              LogStoreName: "sdk-logstore-test",
              Retention:    1,
              Tags:         tags
          }
          err := BLS_CLIENT.CreateLogStoreV2(createLogStoreRequest)
          if err != nil {
            fmt.Println("Create logStore failed: ", err)
          } else {
            fmt.Println("Create logStore success.")
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document Create Logstore

          Update the specified logstore

          With following codes, update the specified logstore, and currently support updating the associated retention period.

          updateLogStoreRequest := UpdateLogStoreRequest{
              Project:      "default",
              LogStoreName: "test",
              Retention:    2,
          }
          err = BLS_CLIENT.UpdateLogStoreV2(updateLogStoreRequest)
          if err != nil {
            fmt.Println("Update logStore failed: ", err)
          } else {
            fmt.Println("Update logStore success.")
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document Update LogStore

          Query the specified logstore

          With following codes, get the specified logstore details.

          describeLogStoreRequest := DescribeLogStoreRequest{
              Project:      "default",
              LogStoreName: "test",
          }
          res, err := BLS_CLIENT.DescribeLogStoreV2(describeLogStoreRequest)
          if err != nil {
            fmt.Println("Get logStore failed: ", err)
          } else {
            fmt.Println("LogStore info: ", res)
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document Describe Logstore

          Get logstore list

          With following codes, obtain the logstore list of the current user.

          //Optional parameter list
          listLogStoreRequest := ListLogStoreRequest{
            Project:     "default"
            NamePattern: "bls-log",
            Order:       "asc",
            OrderBy:     "creationDateTime",
            PageNo:      1,
            PageSize:    10}
          res, err := BLS_CLIENT.ListLogStoreV2(listLogStoreRequest)
          if err != nil {
            fmt.Println("Get logStore list failed: ", err)
          } else {
            fmt.Println("List logStore success: ", res)
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document List Logstore

          Bulk obtain logstore details

          With following codes, bulk obtain the logstore details of the current user

          //Optional parameter list
          batchRequest := bls.BatchLogStoreRequest{
          		LogStores: []bls.BaseLogStore{
          			{
          				Project:      "default",
          				LogStoreName: "bls-test",
          			},
          		},
          	}
          	res, err := BLS_CLIENT.GetLogStoreByProjects(batchRequest)
          	if err != nil {
          		fmt.Println("Batch get logStore failed: ", err)
          	} else {
          		fmt.Println("Batch get logStore success: ", res)
          	}

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document Batch Get Logstore

          Delete logstores

          With following codes, delete the specified logstore and permanently erase all associated logstores that have been stored.

          deleteLogStoreRequest := DeleteLogStoreRequest{
              Project:      "default",
              LogStoreName: "test",
          }
          err = BLS_CLIENT.DeleteLogStoreV2(deleteLogStoreRequest)
          if err != nil {
            fmt.Println("Delete logStore failed: ", err)
          } else {
            fmt.Println("Delete logStore success.")
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document Delete Logstore
          Previous
          Project Operations
          Next
          Download Task Operations