Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if mybatis-plus cannot output through logback-spring

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how mybatis-plus can not output through logback-spring. I hope you will get something after reading this article. Let's discuss it together.

Problem description

Through the official website configuration, mybatis-plus is introduced into the spring boot project, but the log can only be output in the console, but not in the log file of logback.

/ / specific reference URL / / https://mp.baomidou.com/guide/faq.html#%E5%90%AF%E5%8A%A8-mybatis-%E6%9C%AC%E8%BA%AB%E7%9A%84-log-%E6%97%A5%E5%BF%97mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl resolution process

1. Click to view in the StdOutImpl method, which is printed through System.out.println. Logback cannot output this content without configuration.

2. System.out.println is output in logback print file. I found three methods.

Method 1:

System.setOut (new PrintStream (new File ("log path")); System.out.println ()

Method 2: use the jar package

Uk.org.lidalia sysout-over-slf4j 1.0.2

Add to the web.xml file

Uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4JServletContextListener

Method 3: the spring-boot project uses the nohup command to start the output of unspecified log files, and all logs will be output to nohup.out. You can write a shell script regularly, cut the contents of nohup.out by date, and discard the log files output by logback.

This_path=$ (cd `date $0`; pwd) cd $this_path echo $this_path current_date= `date-d "- 1 day" +% Y%m%d "`echo $current_date / / split the specified character size into the new file split-b + 100m-d-a 4 / home/.../nohup.out / home/.../log/log_$ {current_date} _ / / clear nohup.out and wait for the next split cat / dev/null > nohup.out

The above three methods are not suitable for my current needs, and I need to solve this problem from a different point of view, for example, give up using StdOutImpl to output logs

Solution

Discard the use of StdOutImpl output logs and remove the log-impl: org.apache.ibatis.logging.stdout.StdOutImpl configuration. Use a regular logback-spring configuration in application.yml.

Logging: level: com.XXX.mapper: debug

You can output sql statements normally.

After reading this article, I believe you have a certain understanding of "what to do if mybatis-plus cannot output through logback-spring". If you want to know more about it, welcome to follow the industry information channel. Thank you for your reading!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report