【问题标题】:How to DEBUG log only specific statements from a spring-framework class?如何调试仅记录来自 spring-framework 类的特定语句?
【发布时间】:2018-06-14 09:47:28
【问题描述】:

我希望 spring 只记录以下代码行:

this.logger.debug("New connection " + this.getConnectionId());

因此我在application.properties中添加了如下配置: logging.level.org.springframework.integration.ip.tcp.connection.TcpNioConnection=DEBUG

这很好用,但它当然会记录该类中的任何 logger.debug() 语句。

问题:是否可以只记录所需的语句?

【问题讨论】:

    标签: java spring logging


    【解决方案1】:

    解决了它改为监听套接字事件:

    @Component
    public class SocketListener {
        private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
    
        @EventListener
        public void onTcpConnectionOpenEvent(TcpConnectionOpenEvent event) {
            LOGGER.info("new con " + event.getConnectionId());
        }
    
        @EventListener
        public void onTcpConnectionCloseEvent(TcpConnectionCloseEvent event) {
            LOGGER.info("con closed " + event.getConnectionId());
        }
    
        @EventListener
        public void onTcpConnectionOpenEvent(TcpConnectionExceptionEvent event) {
            LOGGER. error("con error " + event.getConnectionId());
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      相关资源
      最近更新 更多