lwb
2021-01-04 5ab01fe1127f842258d86690ef03ec4b1f234ead
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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);
    }
 
}