From fa76f7c56614eba69fd618844f49f50770a1de5b Mon Sep 17 00:00:00 2001 From: Taro Kobayashi Date: Mon, 28 Dec 2015 07:04:19 +0900 Subject: [PATCH] added support for @SuppressLog This is intented to filter out logs for the method within the class annotated with @DebugLog. --- README.md | 15 +++++++++++++++ .../src/main/java/hugo/weaving/SuppressLog.java | 13 +++++++++++++ .../main/java/com/example/hugo/HugoActivity.java | 6 ++++++ .../src/main/java/hugo/weaving/internal/Hugo.java | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 hugo-annotations/src/main/java/hugo/weaving/SuppressLog.java diff --git a/README.md b/README.md index 158aaba..9a866ed 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,21 @@ V/Example: ⇢ getName(first="Jake", last="Wharton") V/Example: ⇠ getName [16ms] = "Jake Wharton" ``` +Add `@SuppressLog` to your methods to suppress the long for specific methods within the class +annotated with `@DebugLog`. + +```java +@DebugLog +static class Charmer { + //... + @SuppressLog + public void doNotLogThis() { + } + //... +} +``` + + The logging will only happen in debug builds and the annotation itself is never present in the compiled class file for any build type. This means you can keep the annotation and check it into source control. It has zero effect on non-debug builds. diff --git a/hugo-annotations/src/main/java/hugo/weaving/SuppressLog.java b/hugo-annotations/src/main/java/hugo/weaving/SuppressLog.java new file mode 100644 index 0000000..481c89e --- /dev/null +++ b/hugo-annotations/src/main/java/hugo/weaving/SuppressLog.java @@ -0,0 +1,13 @@ +package hugo.weaving; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +@Target({TYPE, METHOD, CONSTRUCTOR}) @Retention(CLASS) +public @interface SuppressLog { +} diff --git a/hugo-example/src/main/java/com/example/hugo/HugoActivity.java b/hugo-example/src/main/java/com/example/hugo/HugoActivity.java index a03c7b0..ebc5808 100644 --- a/hugo-example/src/main/java/com/example/hugo/HugoActivity.java +++ b/hugo-example/src/main/java/com/example/hugo/HugoActivity.java @@ -6,6 +6,7 @@ import android.util.Log; import android.widget.TextView; import hugo.weaving.DebugLog; +import hugo.weaving.SuppressLog; public class HugoActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { @@ -23,6 +24,7 @@ public class HugoActivity extends Activity { Charmer charmer = new Charmer("Jake"); Log.d("Charming", charmer.askHowAreYou()); + charmer.doNotLogThis(); startSleepyThread(); } @@ -86,5 +88,9 @@ static class Charmer { public String askHowAreYou() { return "How are you " + name + "?"; } + + @SuppressLog + public void doNotLogThis() { + } } } diff --git a/hugo-runtime/src/main/java/hugo/weaving/internal/Hugo.java b/hugo-runtime/src/main/java/hugo/weaving/internal/Hugo.java index 5997c32..72472a3 100644 --- a/hugo-runtime/src/main/java/hugo/weaving/internal/Hugo.java +++ b/hugo-runtime/src/main/java/hugo/weaving/internal/Hugo.java @@ -20,7 +20,7 @@ public class Hugo { private static volatile boolean enabled = true; - @Pointcut("within(@hugo.weaving.DebugLog *)") + @Pointcut("within(@hugo.weaving.DebugLog *) && !@annotation(hugo.weaving.SuppressLog)") public void withinAnnotatedClass() {} @Pointcut("execution(* *(..)) && withinAnnotatedClass()")