相关疑难解决方法(0)

是否需要执行if(log.isDebugEnabled()){...}检查?

有没有必要做一个明确的if(log.isDebugEnabled()){...}检查?

我的意思是我看到一些帖子提到log.debug("something")在进行日志记录之前进行隐式调用以查看是否已启用调试模式日志记录.我错过了什么,或者在使用之前是否有中间步骤?

谢谢!

log.debug("ResultSet rs is retrieved from OracleTypes");
Run Code Online (Sandbox Code Playgroud)

VS

if(log.isDebugEnabled()){
     log.debug("ResultSet rs is retrieved from OracleTypes");
}
Run Code Online (Sandbox Code Playgroud)

编辑:写了这篇文章:http: //java.sg/whether-to-do-a-isdebugenabled-checking-before-printing-out-your-log-statement/

java logging if-statement log4j

42
推荐指数
4
解决办法
3万
查看次数

ClassNotFoundException:org.slf4j.impl.StaticLoggerBinder

我正在将 spring 应用程序转换为 spring-boot,使用 boot-starter-parent 版本:2.0.4.RELEASE。当我使用 mvn install 构建时,它运行良好,但是当我尝试使用命令运行应用程序时:mvn spring-boot:run -Dspring.profiles.active=dev,我收到此异常: ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder

以下是我的 pom 中的依赖项:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
</parent>

<dependencies>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
    <version>2.0.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.24</version>
  </dependency>
  <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.3.0-alpha4</version>
  </dependency>
  <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.3.0-alpha4</version>
  </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

我尝试遵循此问题的建议,并使用新旧版本的 logback(核心和经典)依赖项,并添加“slf4j-log4j12”和“slf4j-simple”,但仍然出现异常。堆栈跟踪是:

java.lang.NoClassDefFoundError:org/slf4j/impl/StaticLoggerBinder 在 org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext (LogbackLoggingSystem.java:285) 在 org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize (LogbackLoggingSystem) .java:102) 在 org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent (LoggingApplicationListener.java:191) 在 org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent (LoggingApplicationListener.java:170) 在 org. springframework.context.event.SimpleApplicationEventMulticaster.invokeListener (SimpleApplicationEventMulticaster.java:167) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent (SimpleApplicationEventMulticaster.java:139) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent (SimpleApplicationEventMulticaster. java:122)在org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68)在org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)在org.springframework.boot.SpringApplication .run (SpringApplication.java:316) 在 org.springframework.boot.SpringApplication.run (SpringApplication.java:1258) 在 …

logging slf4j spring-boot logback-classic spring-logback

5
推荐指数
1
解决办法
5600
查看次数