android simplified log output method

android simplified log output


The desired effect:

Just need to implement the class ILog interface (without any additional operations), and then you can directly output the log through printLog
as follows:

class A implements ILog{
	void test() {
		printLog("Hello World");
	}
}

Then the result of log output is Log.e(A.getClass().getCanonicalName(),"Hello World");consistent with the output effect.


achieve

The implementation method is also very simple, only two interface definitions can be used directly, but the default implementation of the interface is only slightly used:

public interface ITag {
    default String tag() {
        return this.getClass().getCanonicalName();
    }
}
public interface ILog extends ITag{
    boolean IS_DEBUGGING= true;
    default void printLog(String tagContent) {
        if(IS_DEBUGGING)
        LogUtil.e(tag(), tagContent);
    }
}
Published 312 original articles · won 27 · 130,000 views +

Guess you like

Origin blog.csdn.net/qq_31433709/article/details/105456168