In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "how to display mybatis query log file in logback and write", the content is detailed, the steps are clear, the details are handled properly, I hope this article "how to display mybatis query log file in logback and write" article can help you solve your doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.
Display mybatis query log in logback 1. Configuration file
There are many different implementations. Here is how to output the log to the console.
Mybatis: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl II. Log of the customized package levellogging: level: # your repository package com.kingboy.repository: debug 3. Through the logback-spring.xml file
Add the following configuration to the file
/ / add this section and change it to your own package path to record the operation database sql in the log file
Springboot+mybatis
Mybatis: # Mark the xml file location of the mapper to be parsed mapper-locations: classpath:mapper/*.xml configuration: # org.apache.ibatis.logging.slf4j.Slf4jImpl log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
The specific implementation is to rewrite the StdOutImpl class
The implementation is as follows:
Package com.emily.infrastructure.datasource.log;import com.emily.infrastructure.logback.factory.LogbackFactory;import org.apache.ibatis.logging.Log / * * @ Description: record the mybatis sql statement in the log file to implement the class, which is a replacement for the org.apache.ibatis.logging.stdout.StdOutImpl class * @ Author: Emily* @ create: 2021/8/22*/public class LogBackImpl implements Log {public LogBackImpl (String clazz) {/ / Do Nothing} @ Override public boolean isDebugEnabled () {return true;} @ Override public boolean isTraceEnabled () {return true } @ Override public void error (String s, Throwable e) {LogbackFactory.module ("database", "database", s); e.printStackTrace (System.err);} @ Override public void error (String s) {LogbackFactory.module ("database", "database", s);} @ Override public void debug (String s) {LogbackFactory.module ("database", "database", s) } @ Override public void trace (String s) {LogbackFactory.module ("database", "database", s);} @ Override public void warn (String s) {LogbackFactory.module ("database", "database", s);}}
For the rewritten implementation class to take effect, replace the configuration with the implementation class, as follows:
Mybatis: # Mark the xml file location of mapper to be parsed mapper-locations: classpath:mapper/*.xml configuration: # org.apache.ibatis.logging.slf4j.Slf4jImpl log-impl: com.emily.infrastructure.datasource.log.LogBackImpl. This article "how to display and write mybatis query log files in logback" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.