diff --git a/doc/_content/introduction/deployment.md b/doc/_content/introduction/deployment.md index c347349a..0ee803d8 100644 --- a/doc/_content/introduction/deployment.md +++ b/doc/_content/introduction/deployment.md @@ -28,7 +28,7 @@ jar包: nohup java -jar wvp-pro-*.jar & ``` war包: -下载Tomcat后将war包放入webapps中,启动Tomcat以解压war包,停止Tomcat后,删除ROOT目录以及war包,将解压后的war包目录重命名为ROOT, +下载Tomcat后将war包放入webapps中,启动Tomcat以解压war包,停止Tomcat后,删除ROOT目录以及war包,将解压后的war包目录重命名为ROOT,将配置文件中的Server.port配置为与Tomcat端口一致 然后启动Tomcat。 **启动ZLM** ```shell diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java b/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java index 605e7cf5..cfac446d 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java @@ -65,7 +65,7 @@ public class SipLayer implements CommandLineRunner { private void addListeningPoint(String monitorIp, int port){ SipStackImpl sipStack; try { - sipStack = (SipStackImpl)sipFactory.createSipStack(DefaultProperties.getProperties(monitorIp, false, userSetting.getSipLog())); + sipStack = (SipStackImpl)sipFactory.createSipStack(DefaultProperties.getProperties(monitorIp, userSetting.getSipLog())); } catch (PeerUnavailableException e) { logger.error("[Sip Server] SIP服务启动失败, 监听地址{}失败,请检查ip是否正确", monitorIp); return; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/conf/DefaultProperties.java b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/DefaultProperties.java index 3cdf48dc..59fa8f6d 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/conf/DefaultProperties.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/DefaultProperties.java @@ -12,7 +12,7 @@ import java.util.Properties; */ public class DefaultProperties { - public static Properties getProperties(String ip, boolean isDebug, boolean sipLog) { + public static Properties getProperties(String ip, boolean sipLog) { Properties properties = new Properties(); properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP"); properties.setProperty("javax.sip.IP_ADDRESS", ip); @@ -25,9 +25,6 @@ public class DefaultProperties { */ // * gov/nist/javax/sip/SipStackImpl.class - if (isDebug) { - properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false"); - } // 接收所有notify请求,即使没有订阅 properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "true"); properties.setProperty("gov.nist.javax.sip.AUTOMATIC_DIALOG_ERROR_HANDLING", "false"); @@ -50,29 +47,13 @@ public class DefaultProperties { */ Logger logger = LoggerFactory.getLogger(AlarmNotifyMessageHandler.class); if (sipLog) { - if (logger.isDebugEnabled()) { - System.out.println("DEBUG"); - properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "DEBUG"); - }else if (logger.isInfoEnabled()) { - System.out.println("INFO1"); - properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "INFO"); - }else if (logger.isWarnEnabled()) { - System.out.println("WARNING"); - properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "WARNING"); - }else if (logger.isErrorEnabled()) { - System.out.println("ERROR"); - properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "ERROR"); - }else { - System.out.println("INFO2"); - properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "INFO"); - } - logger.info("[SIP日志]级别为: {}", properties.getProperty("gov.nist.javax.sip.TRACE_LEVEL")); + properties.setProperty("gov.nist.javax.sip.STACK_LOGGER", "com.genersoft.iot.vmp.gb28181.conf.StackLoggerImpl"); + properties.setProperty("gov.nist.javax.sip.SERVER_LOGGER", "com.genersoft.iot.vmp.gb28181.conf.ServerLoggerImpl"); + properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true"); + logger.info("[SIP日志]已开启"); }else { logger.info("[SIP日志]已关闭"); } - - - return properties; } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java new file mode 100644 index 00000000..3fc1d374 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/ServerLoggerImpl.java @@ -0,0 +1,92 @@ +package com.genersoft.iot.vmp.gb28181.conf; + +import gov.nist.core.ServerLogger; +import gov.nist.core.StackLogger; +import gov.nist.javax.sip.message.SIPMessage; +import gov.nist.javax.sip.stack.SIPTransactionStack; + +import javax.sip.SipStack; +import java.util.Properties; + +public class ServerLoggerImpl implements ServerLogger { + + private boolean showLog = true; + + private SIPTransactionStack sipStack; + + protected StackLogger stackLogger; + + @Override + public void closeLogFile() { + + } + + @Override + public void logMessage(SIPMessage message, String from, String to, boolean sender, long time) { + if (!showLog) { + return; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(!sender? "发送:目标--->" + from:"接收:来自--->" + to) + .append("\r\n") + .append(message); + this.stackLogger.logInfo(stringBuilder.toString()); + + } + + @Override + public void logMessage(SIPMessage message, String from, String to, String status, boolean sender, long time) { + if (!showLog) { + return; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(!sender? "发送: 目标->" + from :"接收:来自->" + to) + .append("\r\n") + .append(message); + this.stackLogger.logInfo(stringBuilder.toString()); + } + + @Override + public void logMessage(SIPMessage message, String from, String to, String status, boolean sender) { + if (!showLog) { + return; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(!sender? "发送: 目标->" + from :"接收:来自->" + to) + .append("\r\n") + .append(message); + this.stackLogger.logInfo(stringBuilder.toString()); + } + + @Override + public void logException(Exception ex) { + if (!showLog) { + return; + } + this.stackLogger.logException(ex); + } + + @Override + public void setStackProperties(Properties stackProperties) { + if (!showLog) { + return; + } + String TRACE_LEVEL = stackProperties.getProperty("gov.nist.javax.sip.TRACE_LEVEL"); + if (TRACE_LEVEL != null) { + showLog = true; + } + } + + @Override + public void setSipStack(SipStack sipStack) { + if (!showLog) { + return; + } + if(sipStack instanceof SIPTransactionStack) { + this.sipStack = (SIPTransactionStack)sipStack; + this.stackLogger = this.sipStack.getStackLogger(); + } + } + + +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/conf/StackLoggerImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/StackLoggerImpl.java new file mode 100644 index 00000000..5e67bdba --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/StackLoggerImpl.java @@ -0,0 +1,109 @@ +package com.genersoft.iot.vmp.gb28181.conf; + +import gov.nist.core.StackLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import java.util.Properties; + +@Component +public class StackLoggerImpl implements StackLogger { + + private final static Logger logger = LoggerFactory.getLogger(StackLoggerImpl.class); + + @Override + public void logStackTrace() { + + } + + @Override + public void logStackTrace(int traceLevel) { + System.out.println("traceLevel: " + traceLevel); + } + + @Override + public int getLineCount() { + return 0; + } + + @Override + public void logException(Throwable ex) { + + } + + @Override + public void logDebug(String message) { +// logger.debug(message); + } + + @Override + public void logDebug(String message, Exception ex) { +// logger.debug(message); + } + + @Override + public void logTrace(String message) { + logger.trace(message); + } + + @Override + public void logFatalError(String message) { +// logger.error(message); + } + + @Override + public void logError(String message) { +// logger.error(message); + } + + @Override + public boolean isLoggingEnabled() { + return true; + } + + @Override + public boolean isLoggingEnabled(int logLevel) { + return true; + } + + @Override + public void logError(String message, Exception ex) { +// logger.error(message); + } + + @Override + public void logWarning(String message) { + logger.warn(message); + } + + @Override + public void logInfo(String message) { + logger.info(message); + } + + @Override + public void disableLogging() { + + } + + @Override + public void enableLogging() { + + } + + @Override + public void setBuildTimeStamp(String buildTimeStamp) { + + } + + @Override + public void setStackProperties(Properties stackProperties) { + + } + + @Override + public String getLoggerName() { + return null; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPSender.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPSender.java index 742b8bbb..03ce619c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPSender.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPSender.java @@ -105,7 +105,7 @@ public class SIPSender { } } } finally { - logger.info("[SEND]:SUCCESS:{}", message); +// logger.info("[SEND]:SUCCESS:{}", message); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java index 527b5d09..0c23acea 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java @@ -67,8 +67,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement @Override public void process(RequestEvent evt) { SIPRequest sipRequest = (SIPRequest)evt.getRequest(); - logger.info("接收到消息:" + evt.getRequest()); - logger.debug("接收到消息:" + evt.getRequest()); +// logger.info("接收到消息:" + evt.getRequest()); String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); CallIdHeader callIdHeader = sipRequest.getCallIdHeader(); // 先从会话内查找 diff --git a/src/main/resources/logback-spring-local.xml b/src/main/resources/logback-spring-local.xml index 724d05e4..80d1803b 100644 --- a/src/main/resources/logback-spring-local.xml +++ b/src/main/resources/logback-spring-local.xml @@ -2,16 +2,22 @@ - + + + + + + + - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n + ${log.pattern} + UTF-8 - + DEBUG @@ -32,6 +38,7 @@ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n + UTF-8 @@ -53,32 +60,16 @@ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n + UTF-8 WARN - - - - - - - ${LOG_HOME}/druid-%d{yyyy-MM-dd}.%i.log - - 30 - 50MB - - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n - - - - + ${LOG_HOME}/sip-%d{yyyy-MM-dd}.%i.log @@ -89,6 +80,7 @@ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n + UTF-8 @@ -98,20 +90,13 @@ - + - - - + + - - - - - - \ No newline at end of file