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 7394494..1fd0bfb 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(); } @@ -85,5 +87,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 26ef3d0..8c5dde3 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(!synthetic * *(..)) && withinAnnotatedClass()")