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
<?xml version="1.0" encoding="UTF-8" ?> <configuration scan="true" scanPeriod="3 seconds"> <!--设置日志输出为控制台--> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%logger{32}] %msg%n</pattern> </encoder> </appender> <!--设置日志输出为文件--> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>logFile.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>logFile.%d{yyyy-MM-dd_HH-mm}.log.zip</FileNamePattern> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss,SSS} [%thread] %-5level %logger{32} - %msg%n</Pattern> </layout> </appender> <root> <level value="DEBUG"/> <appender-ref ref="STDOUT"/> <appender-ref ref="FILE"/> </root> </configuration>
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.
Tomcat Native library could not be found using names [tcnative-1, libtcnative-1]
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.
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!