[RemoteLogging] Move init into loghandler (#15780)

Co-authored-by: 旺阳 <wang@lqwang.net>
This commit is contained in:
John Huang 2024-03-31 21:47:26 +08:00 committed by GitHub
parent dc4dad135c
commit d39bdcb165
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 39 deletions

View File

@ -49,19 +49,6 @@ public class GcsRemoteLogHandler implements RemoteLogHandler, Closeable {
private static GcsRemoteLogHandler instance;
private GcsRemoteLogHandler() {
}
public static synchronized GcsRemoteLogHandler getInstance() {
if (instance == null) {
instance = new GcsRemoteLogHandler();
instance.init();
}
return instance;
}
public void init() {
try {
credential = readCredentials();
bucketName = readBucketName();
@ -73,6 +60,14 @@ public class GcsRemoteLogHandler implements RemoteLogHandler, Closeable {
}
}
public static synchronized GcsRemoteLogHandler getInstance() {
if (instance == null) {
instance = new GcsRemoteLogHandler();
}
return instance;
}
@Override
public void close() throws IOException {
try {

View File

@ -44,19 +44,6 @@ public class OssRemoteLogHandler implements RemoteLogHandler, Closeable {
private static OssRemoteLogHandler instance;
private OssRemoteLogHandler() {
}
public static synchronized OssRemoteLogHandler getInstance() {
if (instance == null) {
instance = new OssRemoteLogHandler();
instance.init();
}
return instance;
}
public void init() {
String accessKeyId = readOssAccessKeyId();
String accessKeySecret = readOssAccessKeySecret();
String endpoint = readOssEndpoint();
@ -66,6 +53,14 @@ public class OssRemoteLogHandler implements RemoteLogHandler, Closeable {
checkBucketNameExists(bucketName);
}
public static synchronized OssRemoteLogHandler getInstance() {
if (instance == null) {
instance = new OssRemoteLogHandler();
}
return instance;
}
@Override
public void sendRemoteLog(String logPath) {
String objectName = RemoteLogUtils.getObjectNameFromLogPath(logPath);

View File

@ -56,19 +56,6 @@ public class S3RemoteLogHandler implements RemoteLogHandler, Closeable {
private static S3RemoteLogHandler instance;
private S3RemoteLogHandler() {
}
public static synchronized S3RemoteLogHandler getInstance() {
if (instance == null) {
instance = new S3RemoteLogHandler();
instance.init();
}
return instance;
}
public void init() {
accessKeyId = readAccessKeyID();
accessKeySecret = readAccessKeySecret();
region = readRegion();
@ -78,6 +65,14 @@ public class S3RemoteLogHandler implements RemoteLogHandler, Closeable {
checkBucketNameExists(bucketName);
}
public static synchronized S3RemoteLogHandler getInstance() {
if (instance == null) {
instance = new S3RemoteLogHandler();
}
return instance;
}
protected AmazonS3 buildS3Client() {
if (StringUtils.isNotEmpty(endPoint)) {
return AmazonS3ClientBuilder