mirror of
https://gitee.com/ja-netfilter/ja-netfilter.git
synced 2024-12-22 08:59:25 +08:00
log exceptions
Signed-off-by: pengzhile <pengzhile@gmail.com>
This commit is contained in:
parent
7ba3c94e53
commit
14978ba176
@ -1,4 +1,4 @@
|
||||
# ja-netfilter v2.0.0
|
||||
# ja-netfilter v2.0.1
|
||||
|
||||
### A javaagent framework
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.ja-netfilter</groupId>
|
||||
<artifactId>ja-netfilter</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.1</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -60,7 +60,7 @@ public final class Dispatcher implements ClassFileTransformer {
|
||||
classFileBuffer = transformer.transform(className, classFileBuffer, order++);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
DebugInfo.output("Transform class failed: " + e.getMessage());
|
||||
DebugInfo.output("Transform class failed: " + className, e);
|
||||
}
|
||||
} while (false);
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class Initializer {
|
||||
try {
|
||||
inst.retransformClasses(c);
|
||||
} catch (Throwable e) {
|
||||
DebugInfo.output("Retransform class failed: " + name);
|
||||
DebugInfo.output("Retransform class failed: " + name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.net.URL;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class Launcher {
|
||||
private static final String VERSION = "v2.0.0";
|
||||
private static final String VERSION = "v2.0.1";
|
||||
|
||||
public static void main(String[] args) {
|
||||
printUsage();
|
||||
@ -22,7 +22,7 @@ public class Launcher {
|
||||
try {
|
||||
jarURI = getJarURI();
|
||||
} catch (Throwable e) {
|
||||
DebugInfo.output("ERROR: Can not locate ja-netfilter jar file.");
|
||||
DebugInfo.output("ERROR: Can not locate ja-netfilter jar file.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class Launcher {
|
||||
try {
|
||||
inst.appendToBootstrapClassLoaderSearch(new JarFile(agentFile));
|
||||
} catch (Throwable e) {
|
||||
DebugInfo.output("ERROR: Can not access ja-netfilter jar file.");
|
||||
DebugInfo.output("ERROR: Can not access ja-netfilter jar file.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,11 @@ import com.janetfilter.core.utils.DateUtils;
|
||||
public class DebugInfo {
|
||||
private static final boolean DEBUG = "1".equals(System.getenv("JANF_DEBUG")) || "1".equals(System.getProperty("janf.debug"));
|
||||
|
||||
public static void output(String content) { // No logger lib required
|
||||
public static void output(String content) {
|
||||
output(content, null);
|
||||
}
|
||||
|
||||
public static void output(String content, Throwable e) { // No logger lib required
|
||||
if (!DEBUG) {
|
||||
return;
|
||||
}
|
||||
@ -15,7 +19,15 @@ public class DebugInfo {
|
||||
StackTraceElement[] traces = new Throwable().getStackTrace();
|
||||
String caller = traces.length < 2 ? "UNKNOWN" : traces[1].toString();
|
||||
|
||||
System.out.printf(template, DateUtils.formatNow(), caller, content);
|
||||
System.out.flush();
|
||||
String outContent = String.format(template, DateUtils.formatNow(), caller, content);
|
||||
if (null == e) {
|
||||
System.out.print(outContent);
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (DebugInfo.class) {
|
||||
System.out.print(outContent);
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ public final class PluginManager {
|
||||
}
|
||||
|
||||
public void loadPlugins() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
File pluginsDirectory = environment.getPluginsDir();
|
||||
if (!pluginsDirectory.exists() || !pluginsDirectory.isDirectory()) {
|
||||
return;
|
||||
@ -50,9 +52,9 @@ public final class PluginManager {
|
||||
throw new RuntimeException("Load plugin timeout");
|
||||
}
|
||||
|
||||
DebugInfo.output("============ All plugins loaded ============");
|
||||
DebugInfo.output(String.format("============ All plugins loaded, %.2fs elapsed ============", (System.currentTimeMillis() - startTime) / 1000D));
|
||||
} catch (Throwable e) {
|
||||
DebugInfo.output("Load plugin failed: " + e.getMessage());
|
||||
DebugInfo.output("Load plugin failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +95,7 @@ public final class PluginManager {
|
||||
|
||||
DebugInfo.output("Plugin loaded: {name=" + pluginEntry.getName() + ", version=" + pluginEntry.getVersion() + ", author=" + pluginEntry.getAuthor() + "}");
|
||||
} catch (Throwable e) {
|
||||
DebugInfo.output("Parse plugin info failed: " + e.getMessage());
|
||||
DebugInfo.output("Parse plugin info failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user