百度智能云

All Product Document

          Object Storage

          Log Control

          Application Scenarios

          If the user needs to track the access request of BOS, he/she can enable the function of BOS logging and specify the bucket for logs as well as the file prefix for accessing log. Each access log records the detailed information of a single access request, including requester, bucket name, time of request and operations of request, etc. The log can be applied in access statistics, safety auditing, etc.

          Enable the Bucket Logging

          The following codes enable the bucket logging, and specify the prefix for the access log files that are to be saved eventually:

          bos_client.put_bucket_logging(source_bucket, target_bucket, target_prefix) 

          Note:

          • The user must be the owner of source bucket, have FULL_CONTROL permission, and be the owner of target bucket.
          • Source bucket and target bucket must belong to the same Region.
          • If source bucket enables Logging function, Logging information will also be deleted when source bucket is deleted.
          • If target bucket of Logging is deleted, Logging function of source bucket will be automatically disabled.
          • "targetPrefix" represents the prefix of the name of object where access log records are stored. It can be empty.

          Please refer to PutbucketLogging Interface for details of relevant logging parameters and configuration considerations.

          Inquire the Bucket Logging

          The following codes can view the configuration parameters of bucket logging:

          response = bos_client.get_bucket_logging(bucket_name) 

          The callable parameters in parser class returned by the get_bucket_logging method include:

          Parameter Description
          status Whether the Logging function is enabled
          targetbucket Specify bucket that stores access log. If Logging function is disabled, this field is not included in the response.
          targetPrefix Specify the prefix of access log file that is finally be saved. If Logging function is disabled, this field is not included in the response.

          Disable the Bucket Logging

          The following codes can disable the bucket logging:

          bos_client.delete_bucket_logging(bucket_name)
          Previous
          File Management
          Next
          Exception Handling