Files
BasicDependVersion/njcn-common/src/main/java/com/njcn/common/utils/LogUtil.java
2024-10-30 20:04:37 +08:00

55 lines
1.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.njcn.common.utils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import java.util.List;
/**
* @author hongawen
* @version 1.0
* @data 2024/10/30 14:50
*/
@Slf4j
public class LogUtil {
/**
* 将判断是否开启debug模式抽取单独的方法必要时查看敏感信息
*
* @param log 日志输出器
*/
public static void njcnDebug(Logger log, String format, Object... args) {
if (log.isDebugEnabled()) {
log.info(format, args);
}
}
/**
* 将判断是否开启debug模式抽取单独的方法必要时查看debug级别信息
* 批量输出堆栈日志信息
*
* @param log 日志输出器
*/
public static void njcnPatchDebug(Logger log, List<String> stackInfos) {
if (log.isDebugEnabled()) {
stackInfos.forEach(log::error);
}
}
/**
* 区分是否开启debug模式输出系统异常日志信息
* 若开启debug模式则输出所有的堆栈信息
* 否则只输出第一行日志信息
*
* @param exception 异常
*/
public static void logExceptionStackInfo(String exceptionName, Exception exception) {
//若开启了debug模式则输出所有的栈堆信息
njcnPatchDebug(log, ExceptionUtil.getAllExceptionStackInfo(exception));
log.error("{}{},目标文件:{}",exceptionName, exception, ExceptionUtil.getExceptionServerStackInfo(exception));
}
}