All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pingbu.logger.AndroidLogger Maven / Gradle / Ivy

package pingbu.logger;

import java.lang.reflect.Method;

/**
 * Android logcat日志实现类
 * 
 * @author pingbu
 */
public class AndroidLogger implements LoggerImpl {

    private static final Method sMethodD, sMethodE;

    static {
        Method methodD = null, methodE = null;
        try {
            final Class clazz = Class.forName("android.util.Log");
            methodD = clazz.getDeclaredMethod("d", String.class, String.class);
            methodE = clazz.getDeclaredMethod("e", String.class, String.class);
        } catch (final ReflectiveOperationException e) {
            e.printStackTrace();
        }
        sMethodD = methodD;
        sMethodE = methodE;
    }

    @Override
    public void d(final String tag, final String info) {
        try {
            sMethodD.invoke(null, tag, info);
        } catch (final ReflectiveOperationException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void e(final String tag, final String info) {
        try {
            sMethodE.invoke(null, tag, info);
        } catch (final ReflectiveOperationException e) {
            e.printStackTrace();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy