POST /structuredlog?topic_id=xxxxxxxx-xxxx-xxxx-xxxx HTTP/1.1Host: <Region>.cls.tencentyun.comAuthorization: <AuthorizationString>Content-Type: application/x-protobuf<`LogGroupList` content packaged as a PB file>
${region}.cls.tencentyun.com
, which is only valid for access requests from the same region, that is, CVM or Tencent Cloud services access the CLS service in the same region through the private domain name.${region}.cls.tencentcs.com
. After the access source is connected to the internet, the public domain name of CLS can be accessed under normal circumstances.region
field is the abbreviation of a CLS service region, such as ap-beijing
for the Beijing region. For the complete region list, see Available Regions.ap-beijing - Beijingap-shanghai - Shanghaiap-guangzhou - Guangzhouap-chengdu - Chengdu...
hashkey
, strictly guaranteeing the sequence of the data written to and consumed in this partition.POST /structuredlog?topic_id=xxxxxxxx-xxxx-xxxx-xxxx HTTP/1.1Host: <Region>.cls.tencentyun.comAuthorization: <AuthorizationString>Content-Type: application/x-protobufx-cls-hashkey: xxxxxxxxxxxxxxxxxxxxxxxx<`LogGroupList` content packaged as a PB file>
POST /structuredlog?topic_id=xxxxxxxx-xxxx-xxxx-xxxx HTTP/1.1Host: <Region>.cls.tencentyun.comAuthorization: <AuthorizationString>Content-Type: application/x-protobufx-cls-compress-type:lz4<`LogGroupList` content packaged as a PB file>
POST /structuredlog?topic_id=xxxxxxxx-xxxx-xxxx-xxxx HTTP/1.1Host: <Region>.cls.tencentyun.comAuthorization: <AuthorizationString>Content-Type: application/x-protobuf<`LogGroupList` content packaged as a PB file>
POST /structuredlog
x-cls-hashkey
request header indicates that logs are written to the CLS topic partitions with a range corresponding to the hashkey route, strictly guaranteeing the write sequence of logs to each topic partition for sequential consumption.Field Name | Type | Location | Required | Description |
x-cls-hashkey | string | header | No | Specifies the topic partition to which the logs will be written based on hashkey |
Field Name | Type | Location | Required | Description |
topic_id | string | query | Yes | ID of the target log topic to which data will be uploaded, which can be viewed on the log topic page |
logGroupList | message | pb | Yes | The logGroup list, which describes the encapsulated log groups. No more than five logGroup values are recommended. |
Field Name | Required | Description |
logs | Yes | Log array, which is a set consisting of multiple Log values. A Log indicates a log, and LogGroup can contain up to 10,000 Log values |
contextFlow | No | UID used to maintain context, which does not take effect currently |
filename | No | Log filename |
source | No | Log source, which is generally the server IP |
logTags | No | Tag list of the log |
Field Name | Required | Description |
time | Yes | UNIX timestamp of log time in seconds or milliseconds (recommended) |
contents | No | Log content in key-value format. A log can contain multiple key-value pairs. |
Field Name | Required | Description |
key | Yes | Key of a field group in one log, which cannot start with _ . |
value | Yes | Value of a field group, which cannot exceed 1 MB in one log. The total value cannot exceed 5 MB in LogGroup . |
LogTag
description:Field Name | Required | Description |
key | Yes | Key of a custom tag |
value | Yes | Value corresponding to the custom tag key |
HTTP/1.1 200 OKContent-Length: 0
protobuf-2.6.1.tar.gz
package to /usr/local
and access this directory:[root@VM_0_8_centos]# tar -zxvf protobuf-2.6.1.tar.gz -C /usr/local/ && cd /usr/local/protobuf-2.6.1
[root@VM_0_8_centos protobuf-2.6.1]# ./configure[root@VM_0_8_centos protobuf-2.6.1]# make && make install[root@VM_0_8_centos protobuf-2.6.1]# export PATH=$PATH:/usr/local/protobuf-2.6.1/bin
[root@VM_0_8_centos protobuf-2.6.1]# protoc --versionliprotoc 2.6.1
cls.proto
based on the PB data format content specified by CLS..proto
.cls.proto
(PB description file) is as follows:package cls;message Log{message Content{required string key = 1; // Key of each field grouprequired string value = 2; // Value of each field group}required int64 time = 1; // Unix timestamprepeated Content contents = 2; // Multiple `key-value` pairs in one log}message LogTag{required string key = 1;required string value = 2;}message LogGroup{repeated Log logs = 1; // Log array consisting of multiple logsoptional string contextFlow = 2; // This parameter does not take effect currentlyoptional string filename = 3; // Log filenameoptional string source = 4; // Log source, which is generally the server IPrepeated LogTag logTags = 5;}message LogGroupList{repeated LogGroup logGroupList = 1; // Log group list}
cls.proto
file. Run the following compilation commands:protoc --cpp_out=./ ./cls.proto
--cpp_out=./
indicates that the file will be compiled in cpp format and output to the current directory. ./cls.proto
indicates the cls.proto
description file in the current directory.cls.pb.h
header file and cls.pb.cc
code implementation file.[root@VM_0_8_centos protobuf-2.6.1]# protoc --cpp_out=./ ./cls.proto[root@VM_0_8_centos protobuf-2.6.1]# lscls.pb.cc cls.pb.h cls.proto
cls.pb.h
header file into the code and call the API for data format encapsulation.
Was this page helpful?