diff --git a/README.md b/README.md index 4c1cf2d..f754b1d 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Configuration options: * `CallLogger.enabled`: add to enable this component * `CallLogger.filter`: (optional) restricts functionality to a set of methods, for value format see Method filters section above * `CallLogger.tag`: (optional) log tag to be used (default is `CallLogger`) -* `CallLogger.:`: specifies a call to be logged. `` has to be a full class name like `java.net.URL`. `` can be either a method name like `openConnection` or a more specific method name along with parameter types like `getHeaderField(java.lang.String)`. The value is a format string (see Extended format strings section above). +* `CallLogger.`: specifies that calls to the specified method should be logged. `` is a method specification as outlined in the Method filters section above. Note that `.properties` format requires colons to be prefixed with a backslash: `\:`. The value is a format string (see Extended format strings section above). ## StreamLogger component @@ -68,14 +68,13 @@ Configuration options: ## MethodLogger component -This component will add logging to the start of each method. In addition to the method signature, the parameter values will be logged. +This component will add logging to the start of a method. This might be more efficient than `CallLogger` for methods called from many places, and it will log even calls resulting in an exception. The disadvantage is that the method’s return value cannot be logged as it isn’t known at this stage. Configuration options: * `MethodLogger.enabled`: add to enable this component -* `MethodLogger.filter`: (optional) restricts functionality to a set of methods, for value format see Method filters section above * `MethodLogger.tag`: (optional) log tag to be used (default is `MethodLogger`) -* `MethodLogger.format`: (optional) extended format string to be used, see Extended format strings section above (default is `Entered method {method:%s} ({args:%s})`) +* `MethodLogger.`: specifies a method that should be logged. `` is a method specification as outlined in the Method filters section above. Note that `.properties` format requires colons to be prefixed with a backslash: `\:`. The value is a format string like `Entered method {method:%s} ({args:%s})` (see Extended format strings section above). ## AssignmentRemover component diff --git a/config.properties.example b/config.properties.example index 152c10c..bc99dda 100644 --- a/config.properties.example +++ b/config.properties.example @@ -5,10 +5,9 @@ keystore=debug.jks keypass=123456 MethodLogger.enabled = true -MethodLogger.filter = com.example.funnygame.* \ - com.example.util.Util:* \ - com.example.util.Downloader:download() MethodLogger.tag = MethodEntered +MethodLogger.com.example.funnygame.* = Entered method {method:%s} ({args:%s}) +MethodLogger.com.example.util.Downloader\:download() = Download {this:%x} started AssignmentRemover.enabled = true AssignmentRemover.filter = com.example.funnygame.SomeClass:() diff --git a/src/info/palant/apkInstrumentation/MethodLogger.java b/src/info/palant/apkInstrumentation/MethodLogger.java index ef19bd0..847dba0 100644 --- a/src/info/palant/apkInstrumentation/MethodLogger.java +++ b/src/info/palant/apkInstrumentation/MethodLogger.java @@ -16,36 +16,28 @@ public class MethodLogger extends BodyTransformer { - private final MethodConfig filter; private String tag; - private String format; + private MethodConfig methodConfig; public MethodLogger(Properties config) { - String filterSpec = config.getProperty("MethodLogger.filter"); - if (filterSpec != null) - this.filter = new MethodConfig(filterSpec, ""); - else - this.filter = null; - this.tag = config.getProperty("MethodLogger.tag"); if (tag == null) this.tag = "MethodLogger"; - this.format = config.getProperty("MethodLogger.format"); - if (this.format == null) - this.format = "Entered method {method:%s} ({args:%s})"; + this.methodConfig = new MethodConfig(config, "MethodLogger."); } @Override protected void internalTransform(Body body, String phaseName, Map options) { - if (this.filter != null && this.filter.get(body.getMethod()) == null) + String formatString = this.methodConfig.get(body.getMethod()); + if (formatString == null) return; UnitSequence units = new UnitSequence(body); units.log(this.tag, units.extendedFormat( - this.format, + formatString, null, body.getThisLocal(), body.getParameterLocals().stream().map(local -> (Value)local).collect(Collectors.toList())