Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for @SuppressLog #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions hugo-annotations/src/main/java/hugo/weaving/SuppressLog.java
Original file line number Diff line number Diff line change
@@ -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 {
}
6 changes: 6 additions & 0 deletions hugo-example/src/main/java/com/example/hugo/HugoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -23,6 +24,7 @@ public class HugoActivity extends Activity {

Charmer charmer = new Charmer("Jake");
Log.d("Charming", charmer.askHowAreYou());
charmer.doNotLogThis();

startSleepyThread();
}
Expand Down Expand Up @@ -85,5 +87,9 @@ static class Charmer {
public String askHowAreYou() {
return "How are you " + name + "?";
}

@SuppressLog
public void doNotLogThis() {
}
}
}
2 changes: 1 addition & 1 deletion hugo-runtime/src/main/java/hugo/weaving/internal/Hugo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
Expand Down