Git Product home page Git Product logo

xlog's Introduction

XLog

jcenter Build Status

Method call logging based on dexposed.

What's XLog?

1. XLog a method

Print method calls, arguments, return values, and the execute time by simply add @XLog to a method.

@XLog
public String sayHello(String name) {
    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.

@XLog
public class BaseCalculator {

    public int calculate(int i, int j){
        return i+j;
    }
}

@XLog
public class SampleCalculator extends BaseCalculator {

}


new SampleCalculator().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(new XLogMethod(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 {
    minifyEnabled false  // 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 your Application class

public class MyApplication extends Application {
    public void onCreate() {
        super.onCreate();
        XLogConfig.config(XLogConfig.newConfigBuilder(this)
                    .logMethods(List<XLogMethod> xLogMethod) //optional
                    .timeThreshold(long timeInMillis) // optional
                    .build());
    }
}

Why not Hugo?

Hugo perform bytecode weaving to do the logging, so it cannot work with other bytecode-weaving-based libraries such as retrolambda, 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

xlog's People

Contributors

promeg avatar intrications avatar pylersm avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.