Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logs bug fix. #1382

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public static void install(String artifact, Map<String, Object> argsMap, Instrum
artifactCache = artifact;
adviserCache = new DefaultAdviser();

// 鍒濆鍖栭粯璁ゆ棩蹇�
Copy link
Collaborator

@provenceee provenceee Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

字体编码不对,乱码了

LoggerFactory.initDefaultLogger(artifact);

// 鍒濆鍖栨鏋剁被鍔犺浇鍣�
ClassLoaderManager.init(argsMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public class LoggerFactory {
private LoggerFactory() {
}

/**
* 鍒濆鍖栭粯璁ゆ棩蹇�
*
* @param artifact 褰掑睘浜у搧
*/
public static void initDefaultLogger(String artifact) {
// defaultLogger鐨刵ame蹇呴』涓簊ermant.artifact锛岄渶鍜宻ermantLogger淇濇寔涓�鑷�
defaultLogger = java.util.logging.Logger.getLogger("sermant." + artifact);
}

/**
* 鍒濆鍖杔ogback閰嶇疆鏂囦欢璺緞
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.huaweicloud.sermant.core.exception;

/**
* 网络接口检查异常
* 缃戠粶鎺ュ彛妫�鏌ュ紓甯�
*
* @author tangle
* @since 2023-11-21
Expand All @@ -26,9 +26,9 @@ public class NetInterfacesCheckException extends RuntimeException {
private static final long serialVersionUID = -5485122231044249395L;

/**
* 网络接口检查异常
* 缃戠粶鎺ュ彛妫�鏌ュ紓甯�
*
* @param message 异常信息
* @param message 寮傚父淇℃伅
*/
public NetInterfacesCheckException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundExce
clazz = super.loadClass(name, resolve);
} catch (ClassNotFoundException e) {
// 鎹曡幏绫绘壘涓嶅埌鐨勫紓甯革紝涓嬩竴姝ヤ細杩涘叆localLoader涓幓鍔犺浇绫�
// ignored
LOGGER.log(Level.WARNING, "load class failed, msg is {0}", e.getMessage());
LOGGER.log(Level.FINE, "Load class failed, msg is {0}", e.getMessage());
}
}

Expand All @@ -123,7 +122,7 @@ public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundExce
clazz = loader.loadClass(name);
} catch (ClassNotFoundException e) {
// 鏃犳硶鎵惧埌绫伙紝蹇界暐锛屽悗缁姏鍑哄紓甯�
LOGGER.log(Level.WARNING, "load class failed, msg is {0}", e.getMessage());
LOGGER.log(Level.FINE, "Load class failed, msg is {0}", e.getMessage());
}
}
}
Expand Down Expand Up @@ -157,7 +156,7 @@ public Class<?> loadSermantClass(String name) throws ClassNotFoundException {
clazz = super.loadClass(name, false);
} catch (ClassNotFoundException e) {
// 鏃犳硶鎵惧埌绫伙紝蹇界暐锛屽悗缁姏鍑哄紓甯�
LOGGER.log(Level.WARNING, "load sermant class failed, msg is {0}", e.getMessage());
LOGGER.log(Level.FINE, "Load sermant class failed, msg is {0}", e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public void testInvokeMethod1() {
final Optional<Object> test = ReflectUtils.invokeMethod(TestReflect.class, "test", new Class[]{int.class},
new Object[]{params});
Assert.assertFalse(test.isPresent());

}

@Test
Expand Down Expand Up @@ -116,7 +115,7 @@ public void buildWithConstructor() {
final Optional<Object> result = ReflectUtils.buildWithConstructor(TestReflect.class.getName(), null, null);
Assert.assertTrue(result.isPresent() && result.get() instanceof TestReflect);
final Optional<Object> paramsResult = ReflectUtils.buildWithConstructor(TestReflect.class.getName(),
new Class[] {int.class, int.class},new Object[] {1, 2});
new Class[]{int.class, int.class}, new Object[]{1, 2});
Assert.assertTrue(paramsResult.isPresent() && paramsResult.get() instanceof TestReflect);
final TestReflect reflect = (TestReflect) paramsResult.get();
Assert.assertEquals(reflect.x + reflect.y, 3);
Expand All @@ -127,7 +126,7 @@ public void testBuildWithConstructor() {
final Optional<Object> result = ReflectUtils.buildWithConstructor(TestReflect.class, null, null);
Assert.assertTrue(result.isPresent() && result.get() instanceof TestReflect);
final Optional<Object> paramsResult = ReflectUtils.buildWithConstructor(TestReflect.class,
new Class[] {int.class, int.class},new Object[] {1, 2});
new Class[]{int.class, int.class}, new Object[]{1, 2});
Assert.assertTrue(paramsResult.isPresent() && paramsResult.get() instanceof TestReflect);
final TestReflect reflect = (TestReflect) paramsResult.get();
Assert.assertEquals(reflect.x + reflect.y, 3);
Expand All @@ -138,10 +137,10 @@ public void findConstructor() {
final Optional<Constructor<?>> constructor = ReflectUtils.findConstructor(TestReflect.class, null);
Assert.assertTrue(constructor.isPresent());
final Optional<Constructor<?>> paramsCons = ReflectUtils.findConstructor(TestReflect.class,
new Class[] {int.class, int.class});
new Class[]{int.class, int.class});
Assert.assertTrue(paramsCons.isPresent());
final Optional<Constructor<?>> noFoundCons = ReflectUtils.findConstructor(TestReflect.class,
new Class[] {Integer.class, Integer.class});
new Class[]{Integer.class, Integer.class});
Assert.assertFalse(noFoundCons.isPresent());
}

Expand Down Expand Up @@ -191,7 +190,8 @@ public void getStaticFieldValue() {

@Test
public void getClazzFieldValue() {
final Optional<Object> staticField = ReflectUtils.getFieldValue(TestReflect.class.getName(), null, "staticField");
final Optional<Object> staticField = ReflectUtils.getFieldValue(TestReflect.class.getName(), null,
"staticField");
Assert.assertTrue(staticField.isPresent());
Assert.assertEquals(staticField.get(), TestReflect.staticField);
final Optional<Object> fieldValue = ReflectUtils.getFieldValue("com.test", null, null);
Expand All @@ -213,7 +213,8 @@ public void testGetStaticField() {
Optional<Object> testNullFieldOptional = ReflectUtils.getStaticFieldValue(ReflectUtilsTest.class, null);
Assert.assertNotNull(testNullFieldOptional);
Assert.assertFalse(testNullFieldOptional.isPresent());
Optional<Object> testNotExistOptional = ReflectUtils.getStaticFieldValue(ReflectUtilsTest.class, NOT_EXIST_FIELD_NAME);
Optional<Object> testNotExistOptional = ReflectUtils.getStaticFieldValue(ReflectUtilsTest.class,
NOT_EXIST_FIELD_NAME);
Assert.assertNotNull(testNotExistOptional);
Assert.assertFalse(testNotExistOptional.isPresent());
Optional<Object> testNotStaticOptional = ReflectUtils.getStaticFieldValue(ReflectUtilsTest.class,
Expand All @@ -231,13 +232,15 @@ static class Parent {
}

static class Child extends Parent {

}

static class TestReflect {
private static final String staticField = "staticField";

private final String finalField = "test";

int x;

int y;

TestReflect() {
Expand All @@ -248,6 +251,7 @@ static class TestReflect {
this.x = x;
this.y = y;
}

private String noParams() {
return "noParams";
}
Expand Down
Loading