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

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;
import gov.nist.core.StackLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.spi.LocationAwareLogger;
import org.springframework.stereotype.Component;
import java.util.Properties;
@ -10,100 +10,132 @@ import java.util.Properties;
@Component
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
public void logException(Throwable ex) {
@Override
public void logStackTrace() {
}
}
@Override
public void logDebug(String message) {
// logger.debug(message);
}
@Override
public void logStackTrace(int traceLevel) {
System.out.println("traceLevel: " + traceLevel);
}
@Override
public void logDebug(String message, Exception ex) {
// logger.debug(message);
}
@Override
public int getLineCount() {
return 0;
}
@Override
public void logTrace(String message) {
logger.trace(message);
}
@Override
public void logException(Throwable ex) {
@Override
public void logFatalError(String message) {
// logger.error(message);
}
}
@Override
public void logError(String message) {
// logger.error(message);
}
@Override
public void logDebug(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
@Override
public boolean isLoggingEnabled() {
return true;
}
@Override
public void logDebug(String message, Exception ex) {
log(LocationAwareLogger.INFO_INT, message, ex);
}
@Override
public boolean isLoggingEnabled(int logLevel) {
return true;
}
@Override
public void logTrace(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
@Override
public void logError(String message, Exception ex) {
// logger.error(message);
}
@Override
public void logFatalError(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
@Override
public void logWarning(String message) {
logger.warn(message);
}
@Override
public void logError(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
@Override
public void logInfo(String message) {
logger.info(message);
}
@Override
public boolean isLoggingEnabled() {
return true;
}
@Override
public void disableLogging() {
@Override
public boolean isLoggingEnabled(int logLevel) {
return true;
}
}
@Override
public void logError(String message, Exception ex) {
log(LocationAwareLogger.INFO_INT, message, ex);
}
@Override
public void enableLogging() {
@Override
public void logWarning(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
}
@Override
public void logInfo(String message) {
log(LocationAwareLogger.INFO_INT, message);
}
@Override
public void setBuildTimeStamp(String buildTimeStamp) {
@Override
public void disableLogging() {
}
}
@Override
public void setStackProperties(Properties stackProperties) {
@Override
public void enableLogging() {
}
}
@Override
public String getLoggerName() {
return null;
}
@Override
public void setBuildTimeStamp(String buildTimeStamp) {
}
@Override
public void setStackProperties(Properties stackProperties) {
}
@Override
public String getLoggerName() {
return null;
}
}