Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Method call logging based on dexposed.

License

NotificationsYou must be signed in to change notification settings

promeG/XLog

Repository files navigation

jcenterBuild Status

Method call logging based ondexposed.

What's XLog?

1. XLog a method

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"

2. XLog a class

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

3. XLog more

#####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());

How to use XLog

1. Add XLog to your project.

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}

2. Configure XLog in yourApplication class

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

DebugLog does not work in library module

Libraries' @DebugLog doesn't work

About

Method call logging based on dexposed.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp