-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
70 changed files
with
688 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import com.huaweicloud.sermant.core.classloader.ClassLoaderManager; | ||
import com.huaweicloud.sermant.core.classloader.FrameworkClassLoader; | ||
import com.huaweicloud.sermant.core.exception.LoggerInitException; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
@@ -35,9 +36,9 @@ public class LoggerFactory { | |
|
||
private static final String LOGGER_INIT_METHOD = "init"; | ||
|
||
private static Logger defaultLogger; | ||
private static volatile Logger defaultLogger; | ||
|
||
private static Logger sermantLogger; | ||
private static volatile Logger sermantLogger; | ||
|
||
private LoggerFactory() { | ||
} | ||
|
@@ -50,15 +51,19 @@ private LoggerFactory() { | |
*/ | ||
public static void init(String artifact) { | ||
if (sermantLogger == null) { | ||
FrameworkClassLoader frameworkClassLoader = ClassLoaderManager.getFrameworkClassLoader(); | ||
try { | ||
Method initMethod = frameworkClassLoader | ||
.loadClass(LOGGER_FACTORY_IMPL_CLASS) | ||
.getMethod(LOGGER_INIT_METHOD, String.class); | ||
sermantLogger = (Logger) initMethod.invoke(null, artifact); | ||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | ||
| InvocationTargetException e) { | ||
throw new RuntimeException(e); | ||
synchronized (LoggerFactory.class) { | ||
if (sermantLogger == null) { | ||
FrameworkClassLoader frameworkClassLoader = ClassLoaderManager.getFrameworkClassLoader(); | ||
try { | ||
Method initMethod = frameworkClassLoader | ||
.loadClass(LOGGER_FACTORY_IMPL_CLASS) | ||
.getMethod(LOGGER_INIT_METHOD, String.class); | ||
sermantLogger = (Logger) initMethod.invoke(null, artifact); | ||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | ||
| InvocationTargetException e) { | ||
throw new LoggerInitException(e.getMessage()); | ||
Check failure on line 64 in sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/common/LoggerFactory.java GitHub Actions / Checkstyle
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -75,7 +80,11 @@ public static Logger getLogger() { | |
|
||
// 避免日志重复获取 | ||
if (defaultLogger == null) { | ||
defaultLogger = java.util.logging.Logger.getLogger("sermant"); | ||
synchronized (LoggerFactory.class) { | ||
if (defaultLogger == null) { | ||
defaultLogger = java.util.logging.Logger.getLogger("sermant"); | ||
} | ||
} | ||
} | ||
return defaultLogger; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...entcore-core/src/main/java/com/huaweicloud/sermant/core/exception/FileCheckException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.huaweicloud.sermant.core.exception; | ||
|
||
/** | ||
* 文件检查异常 | ||
* | ||
* @author tangle | ||
* @since 2023-11-07 | ||
*/ | ||
public class FileCheckException extends RuntimeException { | ||
private static final long serialVersionUID = 1339575470808108623L; | ||
|
||
/** | ||
* 文件检查异常 | ||
* | ||
* @param message 异常信息 | ||
*/ | ||
public FileCheckException(String message) { | ||
super(message); | ||
} | ||
} |
Oops, something went wrong.