Charlene
Assistant Engineer
Assistant Engineer
  • UID626
  • Fans0
  • Follows1
  • Posts53
Reads:1860Replies:0

Put Bucket Logging

Created#
More Posted time:Jul 21, 2016 9:47 AM
Put Bucket Logging
The OSS provides bucket access logs for bucket owners to understand and analyze bucket access behaviors in a convenient way. The bucket access logs provided by the OSS do not guarantee that every single access record is logged.

A bucket owner can enable the access logging function for his/her bucket. When this function is enabled, the OSS automatically records detailed information about the requests to this bucket, and follows the user-specified rules to write the access logs as an object into the user-specified bucket hourly.The OSS provides bucket access logs for bucket owners to understand and analyze bucket access behaviors in a convenient way. The bucket access logs provided by the OSS do not guarantee that every single access record is logged.

Request Syntax
  1. PUT /?logging HTTP/1.1
  2. Date: GMT Date
  3. Content-Length: ContentLength
  4. Content-Type: application/xml
  5. Authorization: SignatureValue
  6. Host: BucketName.oss-cn-hangzhou.aliyuncs.com
  7. <?xml version="1.0" encoding="UTF-8"?>
  8. <BucketLoggingStatus>
  9. <LoggingEnabled>
  10. <TargetBucket>TargetBucket</TargetBucket>
  11. <TargetPrefix>TargetPrefix</TargetPrefix>
  12. </LoggingEnabled>
  13. </BucketLoggingStatus>

Request Elements

  Name   Description   Required
  BucketLoggingStatus   Container   for logging status information.
Type: Container
Children:   LoggingEnabled
Ancestry:   None
  Yes
  LoggingEnabled   Container for logging information. This   element is present when
you are enabling logging (and not present when you   are disabling
logging).
Type: Container
Children:   TargetBucket, TargetPrefix
Ancestry:   BucketLoggingStatus
  No
  TargetBucket   Specifies   the bucket where you want Aliyun OSS to store server access logs.
Type: String
Children:   None
Ancestry:   BucketLoggingStatus.LoggingEnabled
  Yes,When   BucketLoggingStatus.LoggingEnabled
  TargetPrefix   This element lets you specify a prefix for   the objects that the log files will be stored.
Type:   String
Children:   None
Ancestry:   BucketLoggingStatus.LoggingEnabled
  No

Naming Rules for the Objects Storing Access Logs

In the naming rules, the TargetPrefix is specified by the user; YYYY, mm, DD, HH, MM and SS give the year, month, day, hour, minutes and seconds of the creation time in Arabic numerals (note the digits); and UniqueString is the string generated by the OSS system. An example for the name of an object actually used to store OSS access logs is given below:

1.MyLog-oss-example-2012-09-10-04-00-00-0000

In the above example, “MyLog-“ is the Object prefix specified by the user;“oss-example” is the name of the origin bucket; “2012-09-10-04-00-00”is the Object creation time (Beijing time); and “0000” is the string generated by the OSS system.

Log File Format

  Name   Example   Description
  Remote IP   119.140.142.11   IP address from which the request is initiated (the proxy or user firewall may block this field)
  Reserved   -   Reserved field
  Reserved   -   Reserved field
  Time   [02/May/2012:00:00:04   +0800]   Time when the OSS receives the request
  Request-URI   “GET /aliyun-logo.png   HTTP/1.1”   User-requested URI (including query-string)
  HTTP Status   200   HTTP status code returned by the OSS
  SentBytes   5576   Traffic that the user downloads from the OSS
  RequestTime (ms)   71   Time spent in completing this request (in ms)
  Referer   http://www.alicloud.com/product/oss   HTTP Referer in the request
  User-Agent   curl/7.15.5   HTTP User-Agent header
  HostName   oss-example.oss-cn-hangzhou.aliyuncs.com   Domain name for access request
  Request ID   505B01695037C2AF032593A4   UUID used to uniquely identify this request
  LoggingFlag   true   Whether the access logging function is enabled
  Reserved   -   Reserved field
  Requester AliCloud ID   1657136103983691   AliCloud ID of the requester, “-“ for anonymous access
  Operation   GetObject   Request type
  Bucket   oss-example   Name of the bucket requested for access
  Key   /aliyun-logo.png   Key of user request
  ObjectSize   5576   Object size
  Server Cost Time (ms)   17   Time taken by the OSS server to process this request (in ms)
  Error Code   NoSuchBucket   Error code returned by the OSS
  Request Length   302   Length of user request (byte)
  UserID   1657136103983691   ID of the bucket owner
  Delta DataSize   280   Bucket size variation, “-“ for no change
  Sync Request   -   Whether this is a request simultaneously generated by a two-node cluster, “-“ for no
  Reserved   -   Reserved field

Example


Example of the request for enabling bucket access logs:
  1. PUT /?logging HTTP/1.1
  2. Host: oss-example.oss-cn-hangzhou.aliyuncs.com
  3. Content-Length: 186
  4. Date: Fri, 04 May 2012 03:21:12 GMT
  5. Authorization: OSS qn6qrrqxo2oawuk53otfjbyc:KU5h8YMUC78M30dXqf3JxrTZHiA=
  6. <?xml version="1.0" encoding="UTF-8"?>
  7. <BucketLoggingStatus>
  8. <LoggingEnabled>
  9. <TargetBucket>doc-log</TargetBucket>
  10. <TargetPrefix>MyLog-</TargetPrefix>
  11. </LoggingEnabled>
  12. </BucketLoggingStatus>


Return example:
  1. HTTP/1.1 200 OK
  2. x-oss-request-id: 19a86d66-3492-0465-12af-7bec0938d0f9
  3. Date: Fri, 04 May 2012 03:21:12 GMT
  4. Content-Length: 0
  5. Connection: close
  6. Server: AliyunOSS


Example of the request for disabling bucket access logs:
  1. PUT /?logging HTTP/1.1
  2. Host: oss-example.oss-cn-hangzhou.aliyuncs.com
  3. Content-Type: application/xml
  4. Content-Length: 86
  5. Date: Fri, 04 May 2012 04:21:12 GMT
  6. Authorization: OSS qn6qrrqxo2oawuk53otfjbyc:KU5h8YMUC78M30dXqf3JxrTZHiA=
  7. <?xml version="1.0" encoding="UTF-8"?>
  8. <BucketLoggingStatus>
  9. </BucketLoggingStatus>


Return example:
  1. HTTP/1.1 200 OK
  2. x-oss-request-id: 5ef71389-094b-0d94-284d-6c4e49c37409
  3. Date: Fri, 04 May 2012 04:21:12 GMT
  4. Content-Length: 0
  5. Connection: close
  6. Server: AliyunOSS
[Charlene edited the post at Jul 22, 2016 9:01 AM]
Guest