- Notifications
You must be signed in to change notification settings - Fork63
Method call logging based on dexposed.
License
promeG/XLog
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Method call logging based ondexposed.
Print method calls, arguments, return values, and the execute time by simply add@XLog
to a method.
@XLogpublicStringsayHello(Stringname) {return"Hello, " +name;}
D/MainActivity: ⇢ sayHello(name="promeg")D/MainActivity: ⇠ sayHello[0ms] = "Hello, promeg"
Log all declared methods and constructors of a class.
This includes public, protected, default (package) access, and private methods or constructors, but excludes inherited ones.
@XLogpublicclassBaseCalculator {publicintcalculate(inti,intj){returni+j; }}@XLogpublicclassSampleCalculatorextendsBaseCalculator {}newSampleCalculator().calculate(1,2);
D/SampleCalculator: ⇢ com.promegu.xloggerexample.SampleCalculator()D/BaseCalculator: ⇢ com.promegu.xloggerexample.BaseCalculator()D/BaseCalculator: ⇠ com.promegu.xloggerexample.BaseCalculator [0ms]D/SampleCalculator: ⇠ com.promegu.xloggerexample.SampleCalculator [0ms]D/BaseCalculator: ⇢ calculate(int=1, int=2)D/BaseCalculator: ⇠ calculate [0ms] = 3
#####XLog a method that you cannot access to the source code
List<XLogMethod>xLogMethods;xLogMethods.add(newXLogMethod(TextView.class,"setText"));XLogConfig.config(XLogConfig.newConfigBuilder(this) .logMethods(xLogMethods) .build());textView.setText("Hello, promeG!");
D/TextView﹕ ⇢ setText(CharSequence="Hello, promeG!")D/TextView﹕ ⇢ setText(CharSequence="Hello, promeG!", BufferType=NORMAL)D/TextView﹕ ⇢ setText(CharSequence="Hello, promeG!", BufferType=NORMAL, boolean=true, int=0)D/TextView﹕ ⇠ setText [0ms]D/TextView﹕ ⇠ setText [0ms]D/TextView﹕ ⇠ setText [0ms]
#####Ignore a method's log if its running time less than a time threshold
XLogConfig.config(XLogConfig.newConfigBuilder(this) .timeThreshold(10) .build());
XLog will do the logging only in debug builds. In release builds, XLog will do noting and the annotation itself will not present.
buildTypes { debug { minifyEnabledfalse// should disable proguard in debug builds... }}dependencies { debugCompile'com.github.promeg:xlog-compiler:2.1.1'// ~6kB debugCompile'com.github.promeg:xlog-android:2.1.1'// ~150kB releaseCompile'com.github.promeg:xlog-android-idle:2.1.1'// ~5kB}
publicclassMyApplicationextendsApplication {publicvoidonCreate() {super.onCreate();XLogConfig.config(XLogConfig.newConfigBuilder(this) .logMethods(List<XLogMethod>xLogMethod)//optional .timeThreshold(longtimeInMillis)// optional .build()); }}
Why notHugo?
Hugo perform bytecode weaving to do the logging, so it cannot work with other bytecode-weaving-based libraries such asretrolambda,loglifecycle.
Moreover, Hugo cannot work on Android Library Module.
XLog solves above problems by using dexposed.
Reference:
Hugo + Retrolambda - is it possible to use both?
Lambdas and Method Reference to work with @DebugLog
About
Method call logging based on dexposed.