18034727885
2026-08-07 237bd0e7494cb73bc351b2e6002831fa593eec4c
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
package cn.sinata.rxnetty;
 
import android.content.Context;
 
import com.blankj.utilcode.util.LogUtils;
 
import java.io.File;
 
public class LogHelper {
    public static File saveLogDir;
 
    public static void initLogs(Context context) {
        LogUtils.Config config = LogUtils.getConfig();
        config.setSaveDays(7);
        config.setFilePrefix("user");
        config.setConsoleSwitch(true);
        config.setLog2FileSwitch(true);
        config.setSingleTagSwitch(true);
        config.setLogHeadSwitch(false);
        saveLogDir = new File(context.getFilesDir(), "logs");
        config.setDir(saveLogDir);
 
        logRecord("initLogs");
    }
 
    public static void logRecord(String info) {
        LogUtils.iTag(getDefaultTag(), info);
    }
 
    private static String getDefaultTag() {
        StackTraceElement[] stacks = new Throwable().getStackTrace();
        StackTraceElement stackTraceElement = stacks[0];
        for (StackTraceElement stack : stacks) {
            if (stack.getClassName().equalsIgnoreCase(stackTraceElement.getClassName())) {
                continue;
            }
            stackTraceElement = stack;
            break;
        }
        String runningClassName = stackTraceElement.getClassName();
        String runningMethodName = stackTraceElement.getMethodName();
        int i = runningClassName.lastIndexOf(".");
        if (i != -1) {
            runningClassName = runningClassName.substring(i + 1);
        }
        Thread thread = Thread.currentThread();
        return "[" + thread.getName() + "-" + thread.getId() + "] " + runningClassName + "." + runningMethodName;
    }
}