diff --git a/README.md b/README.md index a698cd0..8c0a5a6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ja-netfilter v2.0.0 +# ja-netfilter v2.0.1 ### A javaagent framework diff --git a/pom.xml b/pom.xml index 612102e..5164110 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.ja-netfilter ja-netfilter - 2.0.0 + 2.0.1 UTF-8 diff --git a/src/main/java/com/janetfilter/core/Dispatcher.java b/src/main/java/com/janetfilter/core/Dispatcher.java index b269516..167f49d 100644 --- a/src/main/java/com/janetfilter/core/Dispatcher.java +++ b/src/main/java/com/janetfilter/core/Dispatcher.java @@ -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); diff --git a/src/main/java/com/janetfilter/core/Initializer.java b/src/main/java/com/janetfilter/core/Initializer.java index 9d887d6..e827a5c 100644 --- a/src/main/java/com/janetfilter/core/Initializer.java +++ b/src/main/java/com/janetfilter/core/Initializer.java @@ -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); } } } diff --git a/src/main/java/com/janetfilter/core/Launcher.java b/src/main/java/com/janetfilter/core/Launcher.java index dfa71fc..724dad2 100644 --- a/src/main/java/com/janetfilter/core/Launcher.java +++ b/src/main/java/com/janetfilter/core/Launcher.java @@ -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; } diff --git a/src/main/java/com/janetfilter/core/commons/DebugInfo.java b/src/main/java/com/janetfilter/core/commons/DebugInfo.java index d93a1cd..0f54b5d 100644 --- a/src/main/java/com/janetfilter/core/commons/DebugInfo.java +++ b/src/main/java/com/janetfilter/core/commons/DebugInfo.java @@ -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); + } } } diff --git a/src/main/java/com/janetfilter/core/plugin/PluginManager.java b/src/main/java/com/janetfilter/core/plugin/PluginManager.java index 803edef..264637e 100644 --- a/src/main/java/com/janetfilter/core/plugin/PluginManager.java +++ b/src/main/java/com/janetfilter/core/plugin/PluginManager.java @@ -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); } } }