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
|
### A javaagent framework
|
||||||
|
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>com.ja-netfilter</groupId>
|
<groupId>com.ja-netfilter</groupId>
|
||||||
<artifactId>ja-netfilter</artifactId>
|
<artifactId>ja-netfilter</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
|
@ -60,7 +60,7 @@ public final class Dispatcher implements ClassFileTransformer {
|
||||||
classFileBuffer = transformer.transform(className, classFileBuffer, order++);
|
classFileBuffer = transformer.transform(className, classFileBuffer, order++);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
DebugInfo.output("Transform class failed: " + e.getMessage());
|
DebugInfo.output("Transform class failed: " + className, e);
|
||||||
}
|
}
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class Initializer {
|
||||||
try {
|
try {
|
||||||
inst.retransformClasses(c);
|
inst.retransformClasses(c);
|
||||||
} catch (Throwable e) {
|
} 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;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
public class Launcher {
|
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) {
|
public static void main(String[] args) {
|
||||||
printUsage();
|
printUsage();
|
||||||
|
@ -22,7 +22,7 @@ public class Launcher {
|
||||||
try {
|
try {
|
||||||
jarURI = getJarURI();
|
jarURI = getJarURI();
|
||||||
} catch (Throwable e) {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public class Launcher {
|
||||||
try {
|
try {
|
||||||
inst.appendToBootstrapClassLoaderSearch(new JarFile(agentFile));
|
inst.appendToBootstrapClassLoaderSearch(new JarFile(agentFile));
|
||||||
} catch (Throwable e) {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,11 @@ import com.janetfilter.core.utils.DateUtils;
|
||||||
public class DebugInfo {
|
public class DebugInfo {
|
||||||
private static final boolean DEBUG = "1".equals(System.getenv("JANF_DEBUG")) || "1".equals(System.getProperty("janf.debug"));
|
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) {
|
if (!DEBUG) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +19,15 @@ public class DebugInfo {
|
||||||
StackTraceElement[] traces = new Throwable().getStackTrace();
|
StackTraceElement[] traces = new Throwable().getStackTrace();
|
||||||
String caller = traces.length < 2 ? "UNKNOWN" : traces[1].toString();
|
String caller = traces.length < 2 ? "UNKNOWN" : traces[1].toString();
|
||||||
|
|
||||||
System.out.printf(template, DateUtils.formatNow(), caller, content);
|
String outContent = String.format(template, DateUtils.formatNow(), caller, content);
|
||||||
System.out.flush();
|
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() {
|
public void loadPlugins() {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
File pluginsDirectory = environment.getPluginsDir();
|
File pluginsDirectory = environment.getPluginsDir();
|
||||||
if (!pluginsDirectory.exists() || !pluginsDirectory.isDirectory()) {
|
if (!pluginsDirectory.exists() || !pluginsDirectory.isDirectory()) {
|
||||||
return;
|
return;
|
||||||
|
@ -50,9 +52,9 @@ public final class PluginManager {
|
||||||
throw new RuntimeException("Load plugin timeout");
|
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) {
|
} 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() + "}");
|
DebugInfo.output("Plugin loaded: {name=" + pluginEntry.getName() + ", version=" + pluginEntry.getVersion() + ", author=" + pluginEntry.getAuthor() + "}");
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
DebugInfo.output("Parse plugin info failed: " + e.getMessage());
|
DebugInfo.output("Parse plugin info failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue