使用 logback 配置 控制 sip 日志

This commit is contained in:
shikong 2023-08-22 02:12:26 +08:00
parent 431d6f90cb
commit 5599fe010a
7 changed files with 11 additions and 16 deletions

View File

@ -14,7 +14,6 @@ import java.util.List;
@Order(0)
@Data
public class SipConfig {
private List<String> ip;
private List<String> showIp;

View File

@ -1,6 +1,8 @@
package cn.skcks.docking.gb28181.core.sip.logger;
import cn.skcks.docking.gb28181.config.sip.SipConfig;
import gov.nist.core.StackLogger;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -11,7 +11,7 @@ import java.util.Properties;
*/
public class DefaultProperties {
public static Properties getProperties(String name, boolean sipLog) {
public static Properties getProperties(String name) {
Properties properties = new Properties();
properties.setProperty("javax.sip.STACK_NAME", name);
// properties.setProperty("javax.sip.IP_ADDRESS", ip);
@ -49,14 +49,9 @@ public class DefaultProperties {
* sip_server_log.log sip_debug_log.log ERROR, INFO, WARNING, OFF, DEBUG, TRACE
*/
Logger logger = LoggerFactory.getLogger(SipConfig.class);
if (sipLog) {
properties.setProperty("gov.nist.javax.sip.STACK_LOGGER", "cn.skcks.docking.gb28181.core.sip.logger.StackLoggerImpl");
properties.setProperty("gov.nist.javax.sip.SERVER_LOGGER", "cn.skcks.docking.gb28181.core.sip.logger.ServerLoggerImpl");
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
logger.info("[SIP日志]已开启");
}else {
logger.info("[SIP日志]已关闭");
}
properties.setProperty("gov.nist.javax.sip.STACK_LOGGER", "cn.skcks.docking.gb28181.core.sip.logger.StackLoggerImpl");
properties.setProperty("gov.nist.javax.sip.SERVER_LOGGER", "cn.skcks.docking.gb28181.core.sip.logger.ServerLoggerImpl");
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
return properties;
}
}

View File

@ -69,7 +69,7 @@ public class SipServiceImpl implements SipService {
public void listen(String ip, int port){
try{
sipStack = (SipStackImpl)sipFactory.createSipStack(DefaultProperties.getProperties("GB28181_SIP_LOG",true));
sipStack = (SipStackImpl)sipFactory.createSipStack(DefaultProperties.getProperties("GB28181_SIP"));
sipStack.setMessageParserFactory(new GbStringMsgParserFactory());
// sipStack.setMessageProcessorFactory();
try {

View File

@ -1,2 +1,5 @@
server:
port: 28181
project:
version: @project.version@

View File

@ -49,5 +49,6 @@
<!--<appender-ref ref="file" />-->
</root>
<logger name="cn.skcks.docking.gb28181.core.sip.logger" level="INFO" />
<logger name="cn.skcks.docking.gb28181" level="DEBUG" />
</configuration>

View File

@ -2,12 +2,9 @@ package cn.skcks.docking.gb28181.test;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlPath;
import cn.skcks.docking.gb28181.common.json.JsonResponse;
import cn.skcks.docking.gb28181.common.json.JsonUtils;
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
import cn.skcks.docking.gb28181.media.dto.config.FFMpegConfig;
import cn.skcks.docking.gb28181.media.dto.config.HookConfig;
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
import cn.skcks.docking.gb28181.media.dto.media.GetMediaList;
@ -24,7 +21,6 @@ import cn.skcks.docking.gb28181.media.dto.version.VersionResp;
import cn.skcks.docking.gb28181.media.proxy.ZlmMediaService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -34,7 +30,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.net.URL;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;