package com.secondworld.sdk.utils;
|
|
import android.content.Context;
|
import android.util.Log;
|
|
import com.secondworld.sdk.BuildConfig;
|
|
|
public class LogUtil {
|
|
private static final int BUFFER_SIZE = 1024 * 1024; //日志缓存大小
|
|
private static final boolean DEBUG = BuildConfig.DEBUG;
|
|
private static final String GLOBAL_TAG = "Unity-SDK";
|
|
public static void Init(Context context) {
|
// int level = Level.VERBOSE;
|
// Interceptor wrapInterceptor = logData -> {
|
// logData.tag = GLOBAL_TAG + "-" + logData.tag + ":";
|
// return true;
|
// };
|
// AndroidAppender androidAppender = new AndroidAppender.Builder()
|
// .setLevel(level)
|
// .addInterceptor(wrapInterceptor)
|
// .create();
|
//
|
// File logDir = new File(context.getExternalCacheDir() + "/logs/");
|
// String buffer_path = logDir.getAbsolutePath() + File.separator + ".logCache";
|
// String time = new SimpleDateFormat("yyyy_MM_dd", Locale.getDefault()).format(new Date());
|
// String log_path = logDir.getAbsolutePath() + File.separator + time + ".txt";
|
// FileAppender fileAppender = new FileAppender.Builder(context)
|
// .setLogFilePath(log_path)
|
// .setLevel(level)
|
// .addInterceptor(wrapInterceptor)
|
// .setBufferFilePath(buffer_path)
|
// .setFormatter(new DateFileFormatter())
|
// .setCompress(false)
|
// .setBufferSize(BUFFER_SIZE)
|
// .create();
|
//
|
// AppenderLogger logger = new AppenderLogger.Builder()
|
// .addAppender(fileAppender)
|
//// .addAppender(androidAppender)
|
// .create();
|
//
|
// Log4a.setLogger(logger);
|
}
|
|
private static void print(int level, String tag, String msg, boolean debug) {
|
// if (DEBUG || debug)//控制台输出
|
Log.println(level, String.format("%s-%s", GLOBAL_TAG, tag), msg);
|
// else//写入本地文件
|
// Log4a.println(level, tag, msg);
|
}
|
|
public static void debug(String tag, String msg) {
|
print(Log.ERROR, tag, msg, true);
|
}
|
|
public static void v(String tag, String msg) {
|
print(Log.VERBOSE, tag, msg, false);
|
}
|
|
public static void d(String tag, String msg) {
|
print(Log.DEBUG, tag, msg, false);
|
}
|
|
public static void i(String tag, String msg) {
|
print(Log.INFO, tag, msg, false);
|
}
|
|
public static void w(String tag, String msg) {
|
print(Log.WARN, tag, msg, false);
|
}
|
|
public static void e(String tag, String msg) {
|
print(Log.ERROR, tag, msg, false);
|
}
|
|
public static void e(String tag, Exception e) {
|
print(Log.ERROR, tag, Log.getStackTraceString(e), false);
|
}
|
|
}
|