import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.TosClientException;
import com.volcengine.tos.TosServerException;
import com.volcengine.tos.model.bucket.AccessLogConfiguration;
import com.volcengine.tos.model.bucket.PutBucketRealTimeLogInput;
import com.volcengine.tos.model.bucket.PutBucketRealTimeLogOutput;
import com.volcengine.tos.model.bucket.RealTimeLogConfiguration;
public class PutBucketRealTimeLogExample {
public static void main(String[] args) {
String endpoint = "your endpoint";
String region = "your region";
String accessKey = System.getenv("TOS_ACCESS_KEY");
String secretKey = System.getenv("TOS_SECRET_KEY");
String bucketName = "bucket-example";
String realTimeLogRole = "your real time log role";
String tlsProjectId = "the tls project id";
String tlsTopicId = "the tls topic id";
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);
RealTimeLogConfiguration configuration = new RealTimeLogConfiguration().setRole(realTimeLogRole)
.setConfiguration(new AccessLogConfiguration()
.setUseServiceTopic(true)
.setTlsProjectID(tlsProjectId)
.setTlsTopicID(tlsTopicId));
PutBucketRealTimeLogInput input = new PutBucketRealTimeLogInput().setBucket(bucketName)
.setConfiguration(configuration);
PutBucketRealTimeLogOutput output = tos.putBucketRealTimeLog(input);
System.out.println("putBucketRealTimeLog succeed");
} catch (TosClientException e) {
System.out.println("putBucketRealTimeLog failed");
System.out.println("Message: " + e.getMessage());
if (e.getCause() != null) {
e.getCause().printStackTrace();
} catch (TosServerException e) {
System.out.println("putBucketRealTimeLog failed");
System.out.println("StatusCode: " + e.getStatusCode());
System.out.println("Code: " + e.getCode());
System.out.println("Message: " + e.getMessage());
System.out.println("RequestID: " + e.getRequestID());
System.out.println("putBucketRealTimeLog failed");
System.out.println("unexpected exception, message: " + t.getMessage());