Java中如何增加调试行号
import lombok.extern.slf4j.Slf4j; @Slf4j public class LogExample { public void logInfoWithLineNumber(String...args) { try { throw new Exception(); } catch (Exception e) { StackTraceElement element = e.getStackTrace()[1]; log.info("{} - {}-{}", element.getLineNumber(), "这是一条包含行号的日志信息",args); } } public static void main(String[] args) { LogExample example = new LogExample(); example.logInfoWithLineNumber(args); } }