Home  >  Article  >  Java  >  How does Springboot allow logger.debug to output logs?

How does Springboot allow logger.debug to output logs?

WBOY
WBOYforward
2023-05-11 11:40:201180browse

Springboot allows logger.debug to output logs

To be honest, I have always only had a superficial understanding of logs. I will use logger.info and logger.error for output. Today when I was writing the LemonRobot project, I decided Print the debugging information as well, and then control the log level so that debug level logs are not displayed when going online.

But after running it, I found that the logs generated by the default logger.debug were not output to the console. After some research, it was due to a logback configuration issue.

Create a new logback.xml in the sr/main/resources folder, and then copy the following configuration to the file:

logback.xml will be automatically loaded. If the name is different, we need Configure in application.yml or application.properties:

#配置日志
logging:
#此处存放日志的路径
  path:
    config: classpath:config/logback-spring.xml
#指定不同目录下的日志的级别
  level:
    com.shimain.springboot.mapper: DEBUG



    
    
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%logger{32}] %msg%n
        
    
    
    
        logFile.log
        
            logFile.%d{yyyy-MM-dd_HH-mm}.log.zip
        
        
            %d{HH:mm:ss,SSS} [%thread] %-5level %logger{32} - %msg%n
        
    
    
        
        
        
    

This configuration file allows logs to be output to the console and local files at the same time, and the log files are compressed into zip packages.

If the project is online at this time, there is no need for debug logs. You only need to modify the level under the root label to INFO.

SpringBoot starts debug level log error

Tomcat Native library could not be found using names [tcnative-1, libtcnative-1]

Error screenshot

How does Springboot allow logger.debug to output logs?

Cause

tomcat did not find the JNI dynamic link library. There is this dll under Apache Tomcat, but it is not found under Tomcat embedded in Springboot during startup.

This is because in order to improve performance, the connector in Tomcat adopts the method of loading a local library that is bound to the operating system (not cross-platform), such as the .dll dynamic link library in Windows systems.

The two .dll library files that cannot be found in the above exception will be found in Tomcat's bin directory by default. However, since SpringBoot's Tomcat is embedded, there are no these two .dlls.

Solution

You can ignore this error, so SpringBootset the log level of this error to debug.

If you have obsessive-compulsive disorder, you can also solve it as follows:

Directly place tcnative-1.dll and libtcnative-1.dll under tomcat under C:\Windows\System32 , just restart the project.

The above is the detailed content of How does Springboot allow logger.debug to output logs?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete