18034727885
2026-07-31 b386de74c74a4431b2b735eb77c383b71b3ee5b2
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
package cn.sinata.rxnetty;
 
import com.blankj.utilcode.util.LogUtils;
 
public class LogHelper {
 
    public static void initLogs() {
        LogUtils.Config config = LogUtils.getConfig();
        config.setSaveDays(7);
        config.setFilePrefix("gopost");
        config.setConsoleSwitch(true);
        config.setLog2FileSwitch(true);
        config.setSingleTagSwitch(true);
        config.setLogHeadSwitch(false);
 
        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;
    }
}