百度智能云

All Product Document

          Log Service

          LogShipper Operations

          Create logshippers

          To create logshippers, the following guidelines shall be met:

          • More than one logshipper can be created for each logstore
          • Upper limit of total logshippers: 300
          • Logshipper name, at most 63 characters, including letters, digits, - and _
          • The delivery start time can be set to a minimum of 180 days in the past or a maximum of 24 hours in the future. By default, the task creation time is used as the start time. The format must meet ISO 8601.
          createLogShipperRequest := CreateLogShipperRequest{
              LogShipperName: "test",
              Project:        "default",
              LogStoreName:   "test",
              StartTime:      time.Now().UTC().Format("2006-01-02T15:04:05Z"),
              DestType:       "BOS",
              DestConfig: &api.ShipperDestConfig{
                  BOSPath:                  "bls-test/sdk-log-shipper-test/",
                  PartitionFormatTS:        "%Y/%m/%d/%H/%M/",
                  PartitionFormatLogStream: false,
                  MaxObjectSize:            64,
                  CompressType:             "none",
                  DeliverInterval:          5,
                  StorageFormat:            "json",
                  ShipperType:              "text",
              },
          }
          id, err := BLS_CLIENT.CreateLogShipperV2(createLogShipperRequest)
          if err != nil {
            fmt.Println("Create LogShipper failed: ", err)
          } else {
            fmt.Printf("Create LogShipper %s success.", id)
          }

          Prompt:

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

          Update the specified logshipper

          With following codes, update the specified logshipper; currently, logstore, start time and purpose type of logshipper cannot be updated

          updateLogShipperRequest := UpdateLogShipperRequest{
              LogShipperID:   "vxkAJtxc5hGbJIu2JwkqI5Ux",
              LogShipperName: "test",
              DestConfig: &api.ShipperDestConfig{
                  BOSPath:                  "bls-test/sdk-log-shipper-test/",
                  PartitionFormatTS:        "%Y/%m/%d/%H/%M/",
                  PartitionFormatLogStream: false,
                  MaxObjectSize:            128,
                  CompressType:             "none",
                  DeliverInterval:          10,
                  StorageFormat:            "JSON",
              },
          }
          err := BLS_CLIENT.UpdateLogShipperV2(updateLogShipperRequest)
          if err != nil {
            fmt.Println("Update LogShipper failed: ", err)
          } else {
            fmt.Println("Update LogShipper success.")
          }

          Prompt:

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

          Query the specified logshipper

          Use the following code snippets to get the details of the specified logshipper.

          getLogShipperRequest := GetLogShipperRequest{
              LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
          }
          res, err := BLS_CLIENT.GetLogShipperV2(getLogShipperRequest)
          if err != nil {
            fmt.Println("Get LogShipper failed: ", err)
          } else {
            fmt.Println("LogShipper info: ", res)
          }

          Prompt:

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

          Obtain the logshipper list

          Use the following code snippets to query and view logshippers that match the given conditions.

          listLogShipperRequest := ListLogShipperRequest{
              Project:      "default",
              LogStoreName: "test",
              PageNo:       1,
              PageSize:     10,
          }
          res, err := BLS_CLIENT.ListLogShipperV2(listLogShipperRequest)
          if err != nil {
            fmt.Println("Get LogShipper list failed: ", err)
          } else {
            fmt.Println("List LogShipper success: ", res)
          }

          Prompt:

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

          View the logshipper execution record

          Use the following code snippets to review the execution records of the logshipper.

          listShipperRecordRequest := ListShipperRecordRequest{
              LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
          }
          res, err := BLS_CLIENT.ListLogShipperRecordV2(listShipperRecordRequest)
          if err != nil {
            fmt.Println("Get LogShipper record failed: ", err)
          } else {
            fmt.Println("Get LogShipper record success: ", res)
          }

          Prompt:

          Enable/disable logshipper

          Single enable/disable

          Use the following code snippets to enable or disable the specified logshipper.

          updateLogShipperStatusRequest := UpdateLogShipperStatusRequest{
              LogShipperID:  "vxkAJtxc5hGbJIu2JwkqI5Ux",
              DesiredStatus: "Paused",
          }
          err := BLS_CLIENT.UpdateLogShipperStatusV2(updateLogShipperStatusRequest)
          if err != nil {
            fmt.Println("Set LogShipper status failed: ", err)
          } else {
            fmt.Println("Set LogShipper status success.")
          }

          Prompt:

          Bulk enable/disable

          Use the following code snippets to enable or disable multiple logshippers at once.

          bulkUpdateLogShipperStatusRequest := BulkUpdateLogShipperStatusRequest{
              LogShipperIDs: []string{"vxkAJtxc5hGbJIu2JwkqI5Ux"},
              DesiredStatus: "Paused",
          }
          err := BLS_CLIENT.BulkUpdateLogShipperStatusV2(bulkUpdateLogShipperStatusRequest)
          if err != nil {
            fmt.Println("Bulk set LogShipper status failed: ", err)
          } else {
            fmt.Println("Bulk set LogShipper status success.")
          }

          Prompt:

          Delete logshippers

          Single deletion

          Use the following code snippets to delete the specified logshipper.

          deleteLogShipperRequest := DeleteLogShipperRequest{
              LogShipperID: "vxkAJtxc5hGbJIu2JwkqI5Ux",
          }
          err := BLS_CLIENT.DeleteLogShipperV2(deleteLogShipperRequest)
          if err != nil {
            fmt.Println("Delete LogShipper failed: ", err)
          } else {
            fmt.Println("Delete LogShipper success.")
          }

          Prompt:

          Batch delete

          Using the following code, you can bulk delete logshippers.

          bulkDeleteLogShipperRequest := BulkDeleteLogShipperRequest{
              LogShipperIDs: []string{"vxkAJtxc5hGbJIu2JwkqI5Ux"},
          }
          err := BLS_CLIENT.BulkDeleteLogShipperV2(bulkDeleteLogShipperRequest)
          if err != nil {
            fmt.Println("Bulk delete LogShipper failed: ", err)
          } else {
            fmt.Println("Bulk delete LogShipper success.")
          }

          Prompt:

          Previous
          LogStream Operations
          Next
          Version Release Records