增加日志记录时的完全限定类名,用于定位日志位置。
ps:2023-12-12 16:30:58.779 [Thread-10] INFO --- gov.nist.javax.sip.stack.UDPMessageChannel : 81 Done processing MESSAGE sip:44010200492000000003@4401020049 SIP/2.0 日志中的“gov.nist.javax.sip.stack.UDPMessageChannel”内容pull/1205/head
parent
5a9621840c
commit
360fe689b1
|
@ -1,8 +1,8 @@
|
||||||
package com.genersoft.iot.vmp.gb28181.conf;
|
package com.genersoft.iot.vmp.gb28181.conf;
|
||||||
|
|
||||||
import gov.nist.core.StackLogger;
|
import gov.nist.core.StackLogger;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.slf4j.spi.LocationAwareLogger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -10,7 +10,39 @@ import java.util.Properties;
|
||||||
@Component
|
@Component
|
||||||
public class StackLoggerImpl implements StackLogger {
|
public class StackLoggerImpl implements StackLogger {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(StackLoggerImpl.class);
|
/**
|
||||||
|
* 完全限定类名(Fully Qualified Class Name),用于定位日志位置
|
||||||
|
*/
|
||||||
|
private static final String FQCN = StackLoggerImpl.class.getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取栈中类信息(以便底层日志记录系统能够提取正确的位置信息(方法名、行号))
|
||||||
|
* @return LocationAwareLogger
|
||||||
|
*/
|
||||||
|
private static LocationAwareLogger getLocationAwareLogger() {
|
||||||
|
return (LocationAwareLogger) LoggerFactory.getLogger(new Throwable().getStackTrace()[4].getClassName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装打印日志的位置信息
|
||||||
|
* @param level 日志级别
|
||||||
|
* @param message 日志事件的消息
|
||||||
|
*/
|
||||||
|
private static void log(int level, String message) {
|
||||||
|
LocationAwareLogger locationAwareLogger = getLocationAwareLogger();
|
||||||
|
locationAwareLogger.log(null, FQCN, level, message, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装打印日志的位置信息
|
||||||
|
* @param level 日志级别
|
||||||
|
* @param message 日志事件的消息
|
||||||
|
*/
|
||||||
|
private static void log(int level, String message, Throwable throwable) {
|
||||||
|
LocationAwareLogger locationAwareLogger = getLocationAwareLogger();
|
||||||
|
locationAwareLogger.log(null, FQCN, level, message, null, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logStackTrace() {
|
public void logStackTrace() {
|
||||||
|
@ -34,27 +66,27 @@ public class StackLoggerImpl implements StackLogger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logDebug(String message) {
|
public void logDebug(String message) {
|
||||||
// logger.debug(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logDebug(String message, Exception ex) {
|
public void logDebug(String message, Exception ex) {
|
||||||
// logger.debug(message);
|
log(LocationAwareLogger.INFO_INT, message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logTrace(String message) {
|
public void logTrace(String message) {
|
||||||
logger.trace(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logFatalError(String message) {
|
public void logFatalError(String message) {
|
||||||
// logger.error(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logError(String message) {
|
public void logError(String message) {
|
||||||
// logger.error(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,17 +101,17 @@ public class StackLoggerImpl implements StackLogger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logError(String message, Exception ex) {
|
public void logError(String message, Exception ex) {
|
||||||
// logger.error(message);
|
log(LocationAwareLogger.INFO_INT, message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logWarning(String message) {
|
public void logWarning(String message) {
|
||||||
logger.warn(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logInfo(String message) {
|
public void logInfo(String message) {
|
||||||
logger.info(message);
|
log(LocationAwareLogger.INFO_INT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue