Object Storage Service (OSS) logs a standard set of fields in access logs for basic analytical purposes. In some scenarios, you may want to log custom fields to implement fine-grained user behavior tracking and analysis or tailor information monitoring. In this case, you can configure custom log fields to record request headers and query parameters that you want to monitor. Custom log fields are aggregated in the user_defined_log_fields field.
Background information
An HTTP request is largely characterized by its request headers and query parameters. OSS access logs record only a portion of the request characteristics by default. For more information about OSS access logs, see Access logs.
To monitor data of concern to you, you can configure OSS to additionally record request headers and query parameters. For more information about request headers and query parameters, see RFC 2616.
Scenarios
Proxy analysis: Standard OSS logs do not record the
x-forwarded-forheader. In cases where you want to monitor the header for intermediary analysis, you can configure a custom log field to log the header.Request categorization based on query parameters: Standard OSS logs do not record query parameters in a request URL. If you want to log query parameters, such as rrr and eee in the
http://bucketname.aliyuncs.com/hu.jpg?yyy=45&eee=88&rrr=huyanbinURL, you can configure custom log fields to log the parameters.
Usage notes
Each line holds only one request header or query parameter. You can specify a total of six request headers and query parameters.
Your logging configuration information is encoded and populated in the
user_defined_log_fieldsfield. The value of theuser_defined_log_fieldsfield is Base64-encoded JSON data. The JSON data includes the "truncated" field that indicates whether the JSON data was truncated, the "headers" field that contains the specified request headers, and the "querys" field that contains the specified query parameters.Custom field keys for request headers can contain hyphens (-) but cannot contain underscores (_). Custom field keys for query parameters can contain underscores (_).
Custom field keys for request headers must comply with the HTTP protocol and can contain only ASCII printable characters (from 33 to 126) except for underscores (_) and colons (:).
The total key and value length of all custom fields for request headers and query parameters cannot exceed the limit of 1,024 bytes. Trailing data beyond the limit is truncated. The keys of custom log fields are converted to lower case in logs. No case conversion is applied to the values of custom log fields. Log field values represent information sent in the requests and are truncated if the length limit is exceeded.
Prerequisites
The real-time log query feature is enabled for the bucket. For more information, see Real-time log query.
The requests sent to the bucket contain the related request headers or query parameters. For more information, see Initiate a request.
Methods
Use the OSS console
Use ossutil
Related API operation
The methods described above are fundamentally implemented based on the RESTful API, which you can directly call if your business requires a high level of customization. To directly call an API, you must include the signature calculation in your code. For more information, see PutUserDefinedLogFieldsConfig.