增加日志记录时的完全限定类名,用于定位日志位置。

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
xubinbin 2023-12-12 16:41:15 +08:00
parent 5a9621840c
commit 360fe689b1
1 changed files with 104 additions and 72 deletions

View File

@ -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,100 +10,132 @@ 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();
@Override /**
public void logStackTrace() { * (便())
* @return LocationAwareLogger
*/
private static LocationAwareLogger getLocationAwareLogger() {
return (LocationAwareLogger) LoggerFactory.getLogger(new Throwable().getStackTrace()[4].getClassName());
}
}
@Override /**
public void logStackTrace(int traceLevel) { *
System.out.println("traceLevel: " + traceLevel); * @param level
} * @param message
*/
private static void log(int level, String message) {
LocationAwareLogger locationAwareLogger = getLocationAwareLogger();
locationAwareLogger.log(null, FQCN, level, message, null, null);
}
@Override /**
public int getLineCount() { *
return 0; * @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 logException(Throwable ex) { public void logStackTrace() {
} }
@Override @Override
public void logDebug(String message) { public void logStackTrace(int traceLevel) {
// logger.debug(message); System.out.println("traceLevel: " + traceLevel);
} }
@Override @Override
public void logDebug(String message, Exception ex) { public int getLineCount() {
// logger.debug(message); return 0;
} }
@Override @Override
public void logTrace(String message) { public void logException(Throwable ex) {
logger.trace(message);
}
@Override }
public void logFatalError(String message) {
// logger.error(message);
}
@Override @Override
public void logError(String message) { public void logDebug(String message) {
// logger.error(message); log(LocationAwareLogger.INFO_INT, message);
} }
@Override @Override
public boolean isLoggingEnabled() { public void logDebug(String message, Exception ex) {
return true; log(LocationAwareLogger.INFO_INT, message, ex);
} }
@Override @Override
public boolean isLoggingEnabled(int logLevel) { public void logTrace(String message) {
return true; log(LocationAwareLogger.INFO_INT, message);
} }
@Override @Override
public void logError(String message, Exception ex) { public void logFatalError(String message) {
// logger.error(message); log(LocationAwareLogger.INFO_INT, message);
} }
@Override @Override
public void logWarning(String message) { public void logError(String message) {
logger.warn(message); log(LocationAwareLogger.INFO_INT, message);
} }
@Override @Override
public void logInfo(String message) { public boolean isLoggingEnabled() {
logger.info(message); return true;
} }
@Override @Override
public void disableLogging() { public boolean isLoggingEnabled(int logLevel) {
return true;
}
} @Override
public void logError(String message, Exception ex) {
log(LocationAwareLogger.INFO_INT, message, ex);
}
@Override @Override
public void enableLogging() { public void logWarning(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
} @Override
public void logInfo(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
@Override @Override
public void setBuildTimeStamp(String buildTimeStamp) { public void disableLogging() {
} }
@Override @Override
public void setStackProperties(Properties stackProperties) { public void enableLogging() {
} }
@Override @Override
public String getLoggerName() { public void setBuildTimeStamp(String buildTimeStamp) {
return null;
} }
@Override
public void setStackProperties(Properties stackProperties) {
}
@Override
public String getLoggerName() {
return null;
}
} }