You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Manage Bucket Configuration
Managing Real-Time Logs (C++ SDK)
Copy page
Download PDF
Managing Real-Time Logs (C++ SDK)
TOS provides log analysis capabilities, enabling you to retrieve and analyze access logs generated during your use of TOS through the log service. You can configure the relevant settings for log analysis functionality through the TOS C++ SDK.​
Configure real-time log configuration rules​
warning​
  • To use the log analysis feature, you must have enabled the log service and authorized TOS to access Volcengine Log Service (TLS).​
  • After the log analysis feature is enabled, the logging service automatically creates log projects and topics to store logs related to TOS.​
Sample Code​
The following code is used to configure real-time log configuration rules for the bucket examplebucket.​
​
#include "TosClientV2.h"​
using namespace VolcengineTos;​
​
int main(void){​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
std::string bucketName = "examplebucket";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
​
PutBucketRealTimeLogInput input(bucketName);​
​
AccessLogConfiguration accessLogConfiguration;​
​
accessLogConfiguration.setUseServiceTopic(true);​
​
// accessLogConfiguration.setUseServiceTopic(false);​
// accessLogConfiguration.setTlsProjectId("Your Tls Project Id");​
// accessLogConfiguration.setTlsTopicId("Your Tls Topic Id");​
​
RealTimeLogConfiguration realTimeLogConfiguration;​
​
realTimeLogConfiguration.setRole("TOSLogArchiveTLSRole");​
​
realTimeLogConfiguration.setConfiguration(accessLogConfiguration);​
​
input.setConfiguration(realTimeLogConfiguration);​
auto output = client.putBucketRealTimeLog(input);​
if (!output.isSuccess()) {​
​
std::cout << "PutBucketRealTimeLog failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
std::cout << "PutBucketRealTimeLog success." << std::endl;​
​
​
CloseClient();​
return 0;​
}​
​
Retrieve Real-Time Log Configuration Rules​
warning​
To obtain the real-time log configuration rules for a bucket, you must, by default, be the bucket owner.​
Sample Code​
The following code is used to retrieve the real-time log configuration rules for the bucket 'examplebucket.'​
​
#include "TosClientV2.h"​
using namespace VolcengineTos;​
​
int main(void){​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
std::string bucketName = "examplebucket";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
GetBucketRealTimeLogInput input(bucketName);​
​
auto output = client.getBucketRealTimeLog(input);​
if (!output.isSuccess()) {​
​
std::cout << "GetBucketRealTimeLog failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
std::cout << "GetBucketRealTimeLog success." << std::endl;​
auto config = output.result().getConfiguration();​
std::cout << "role:" << config.getRole() << std::endl;​
std::cout << "is use service topic:" << config.getConfiguration().isUseServiceTopic() << std::endl;​
std::cout << "project id:" << config.getConfiguration().getTlsProjectId() << std::endl;​
std::cout << "tls topic id:" << config.getConfiguration().getTlsTopicId() << std::endl;​
​
​
CloseClient();​
return 0;​
}​
​
Delete Real-Time Log Configuration Rules​
warning​
To delete the real-time log configuration rules of a bucket, you must, by default, be the bucket owner.​
Sample Code​
The following code is used to delete the real-time log configuration rule for the bucket 'examplebucket.'​
​
#include "TosClientV2.h"​
using namespace VolcengineTos;​
​
int main(void){​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
std::string bucketName = "examplebucket";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
DeleteBucketRealTimeLogInput input(bucketName);​
auto output = client.deleteBucketRealTimeLog(input);​
if (!output.isSuccess()) {​
​
std::cout << "DeleteBucketRealTimeLog failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
std::cout << "DeleteBucketRealTimeLog success." << std::endl;​
​
CloseClient();​
return 0;​
}​
​
Relevant Documentation​
For more information on real-time log configuration, see Log Analysis.​
Last updated: 2025.09.25 14:22:46