reduce log reset frequency

This commit is contained in:
金戟 2020-12-07 23:26:18 +08:00
parent 65807eece7
commit bd0ec5f4b7

View File

@ -40,22 +40,24 @@ public class TestableClassTransformer implements ClassFileTransformer {
// Ignore system class and reloaded class // Ignore system class and reloaded class
return null; return null;
} }
byte[] bytes = null;
try { try {
if (shouldTransformAsSourceClass(className)) { if (shouldTransformAsSourceClass(className)) {
// it's a source class with testable enabled // it's a source class with testable enabled
LogUtil.diagnose("Handling source class %s", className); LogUtil.diagnose("Handling source class %s", className);
List<MethodInfo> injectMethods = getTestableMockMethods(ClassUtil.getTestClassName(className)); List<MethodInfo> injectMethods = getTestableMockMethods(ClassUtil.getTestClassName(className));
return new SourceClassHandler(injectMethods).getBytes(classFileBuffer); bytes = new SourceClassHandler(injectMethods).getBytes(classFileBuffer);
resetMockContext();
} else if (shouldTransformAsTestClass(className)) { } else if (shouldTransformAsTestClass(className)) {
// it's a test class with testable enabled // it's a test class with testable enabled
LogUtil.diagnose("Handling test class %s", className); LogUtil.diagnose("Handling test class %s", className);
return new TestClassHandler().getBytes(classFileBuffer); bytes = new TestClassHandler().getBytes(classFileBuffer);
resetMockContext();
} }
LogUtil.resetLogLevel();
} catch (IOException e) { } catch (IOException e) {
return null; LogUtil.warn("Failed to transform class " + className);
} }
return null; return bytes;
} }
private boolean shouldTransformAsSourceClass(String className) { private boolean shouldTransformAsSourceClass(String className) {
@ -155,6 +157,10 @@ public class TestableClassTransformer implements ClassFileTransformer {
} }
} }
private void resetMockContext() {
LogUtil.resetLogLevel();
}
/** /**
* Split desc to "first parameter" and "desc of rest parameters" * Split desc to "first parameter" and "desc of rest parameters"
* @param desc method desc * @param desc method desc