mirror of
https://gitee.com/ja-netfilter/ja-netfilter.git
synced 2024-12-22 08:59:25 +08:00
hide debug info by default
Signed-off-by: pengzhile <pengzhile@gmail.com>
This commit is contained in:
parent
8a0cc23737
commit
f4a6ff6d43
@ -20,7 +20,6 @@ public class Launcher {
|
||||
}
|
||||
|
||||
try {
|
||||
jarURL = new URL("file:/Users/neo/Downloads/ja-netfilter/target/ja-netfilter-jar-with-dependencies.jar");
|
||||
inst.appendToBootstrapClassLoaderSearch(new JarFile(jarURL.getPath()));
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Can not access ja-netfilter jar file.", e);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.zhile.research.ja.netfilter;
|
||||
|
||||
import io.zhile.research.ja.netfilter.commons.DebugInfo;
|
||||
import io.zhile.research.ja.netfilter.transformers.HttpClientTransformer;
|
||||
import io.zhile.research.ja.netfilter.transformers.InetAddressTransformer;
|
||||
import io.zhile.research.ja.netfilter.transformers.MyTransformer;
|
||||
@ -33,7 +34,7 @@ public class TransformDispatcher implements ClassFileTransformer {
|
||||
try {
|
||||
return transformer.transform(className, classFileBuffer);
|
||||
} catch (Exception e) {
|
||||
System.out.println("=== Transform class failed: " + e.getMessage());
|
||||
DebugInfo.output("=== Transform class failed: " + e.getMessage());
|
||||
}
|
||||
} while (false);
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
package io.zhile.research.ja.netfilter.commons;
|
||||
|
||||
import io.zhile.research.ja.netfilter.utils.DateUtils;
|
||||
|
||||
public class DebugInfo {
|
||||
private static final boolean DEBUG = "1".equals(System.getenv("JANF_DEBUG"));
|
||||
|
||||
public static void output(String content) { // No logger lib required
|
||||
if (!DEBUG) {
|
||||
return;
|
||||
}
|
||||
|
||||
String template = "[%s] %s DEBUG : %s%n";
|
||||
|
||||
StackTraceElement[] traces = new Throwable().getStackTrace();
|
||||
String caller = traces.length < 2 ? "UNKNOWN" : traces[1].toString();
|
||||
|
||||
System.out.printf(template, DateUtils.formatNow(), caller, content);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package io.zhile.research.ja.netfilter.filters;
|
||||
|
||||
import io.zhile.research.ja.netfilter.commons.DebugInfo;
|
||||
import io.zhile.research.ja.netfilter.enums.RuleType;
|
||||
import io.zhile.research.ja.netfilter.models.FilterRule;
|
||||
|
||||
@ -26,7 +27,7 @@ public class DNSFilter {
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("=== reject dns query: " + host + ", rule: " + rule);
|
||||
DebugInfo.output("=== reject dns query: " + host + ", rule: " + rule);
|
||||
throw new java.net.UnknownHostException();
|
||||
}
|
||||
|
||||
@ -43,7 +44,7 @@ public class DNSFilter {
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("=== reject dns reachable test: " + n.getHostName() + ", rule: " + rule);
|
||||
DebugInfo.output("=== reject dns reachable test: " + n.getHostName() + ", rule: " + rule);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.zhile.research.ja.netfilter.filters;
|
||||
|
||||
import io.zhile.research.ja.netfilter.commons.DebugInfo;
|
||||
import io.zhile.research.ja.netfilter.enums.RuleType;
|
||||
import io.zhile.research.ja.netfilter.models.FilterRule;
|
||||
|
||||
@ -27,7 +28,7 @@ public class URLFilter {
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("=== reject url: " + url + ", rule: " + rule);
|
||||
DebugInfo.output("=== reject url: " + url + ", rule: " + rule);
|
||||
throw new SocketTimeoutException("connect timed out");
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
package io.zhile.research.ja.netfilter.utils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateUtils {
|
||||
public static final DateFormat FULL_DF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
public static final DateFormat DATE_DF = new SimpleDateFormat("yyyy-MM-dd");
|
||||
public static final DateFormat TIME_DF = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
public static String formatDateTime(Date date) {
|
||||
return FULL_DF.format(date);
|
||||
}
|
||||
|
||||
public static String formatDate(Date date) {
|
||||
return DATE_DF.format(date);
|
||||
}
|
||||
|
||||
public static String formatTime(Date date) {
|
||||
return TIME_DF.format(date);
|
||||
}
|
||||
|
||||
public static Date parseTime(String timeStr) throws ParseException {
|
||||
return TIME_DF.parse(timeStr);
|
||||
}
|
||||
|
||||
public static Date parseDate(String dateStr) throws ParseException {
|
||||
return DATE_DF.parse(dateStr);
|
||||
}
|
||||
|
||||
public static Date parseDateTime(String dateTimeStr) throws ParseException {
|
||||
return FULL_DF.parse(dateTimeStr);
|
||||
}
|
||||
|
||||
public static String formatNow() {
|
||||
return formatDateTime(new Date());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user