package com.hitech.jni4cppdemo.utils;
public class Log {
// 应用名称
private static final String TAG = "ResX*";
// 日志开关
private static boolean switches = false;
// 日志级别
private static int level = android.util.Log.VERBOSE;
public static void v(Object log) {
if (switches) {
if (level <= android.util.Log.VERBOSE) {
if (functionName() != null) {
android.util.Log.v(TAG, functionName() + log);
} else {
android.util.Log.v(TAG, log.toString());
}
}
}
}
public static void d(Object log) {
if (switches) {
if (level <= android.util.Log.DEBUG) {
if (functionName() != null) {
android.util.Log.d(TAG, functionName() + log);
} else {
android.util.Log.d(TAG, log.toString());
}
}
}
}
public static void i(Object log) {
if (switches) {
if (level <= android.util.Log.INFO) {
if (functionName() != null) {
android.util.Log.i(TAG, functionName() + log);
} else {
android.util.Log.i(TAG, log.toString());
}
}
}
}
public static void w(Object log) {
if (switches) {
if (level <= android.util.Log.WARN) {
if (functionName() != null) {
android.util.Log.w(TAG, functionName() + log);
} else {
android.util.Log.w(TAG, log.toString());
}
}
}
}
public static void e(Object log) {
if (switches) {
if (level <= android.util.Log.ERROR) {
if (functionName() != null) {
android.util.Log.e(TAG, functionName() + log);
} else {
android.util.Log.e(TAG, log.toString());
}
}
}
}
private static String functionName() {
StackTraceElement[] sts = Thread.currentThread().getStackTrace();
if (sts == null) {
return null;
}
for (StackTraceElement st : sts) {
if (st.isNativeMethod()) {
continue;
}
if (st.getClassName().equals(Thread.class.getName())) {
continue;
}
if (st.getClassName().equals(Log.class.getName())) {
continue;
}
return "at " + st.getFileName() + ", line " + st.getLineNumber()
+ ", method:" + st.getMethodName() + ", ";
// return "Thread:" + Thread.currentThread().getName() + "; Source:"
// + st.getFileName() + "\nAt line:" + st.getLineNumber()
// + "; Method:" + st.getMethodName();
}
return null;
}
}