引的是 slf4j 包
import org.slf4j.logger;import org.slf4j.loggerfactory;private static logger logger = loggerfactory.getlogger(tsftest.class);logger.info("打印参数:",map);
只能打印出:
2019-06-14 17:52:07.246 [http-apr-8080-exec-10] info c.q.m.p.b.rest.test – 打印参数:
在第一个参数中加入花括号{ }即可。
logger.info("打印参数:{}",map);
解决!
在resouces目录下面新建logback.xml(此为logback推荐目录)
内容配置如下
logback 分为两种设置:
1. 输出到控制台 stdout
2. 输出到文件 file
<properties> <slf4j.version>1.7.25</slf4j.version></properties><dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <version>${slf4j.version}</version></dependency><dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>1.7.25</version></dependency>
下面的配置同时配置输出到文件和输出到控制台
<?xml version="1.0" encoding="utf-8" ?><configuration scan="true" scanperiod="3 conds"> <!--设置日志输出为控制台--> <appender name="stdout" class="ch.qos.logback.core.consoleappender"> <encoder> <pattern>%d{yyyy-mm-dd hh:mm:ss.sss} %-5level [%x{urid}] [%x{requestid}] %logger - %m2020端午节是几号sg%n</pattern> </encoder> </appender> <!--设置日志输出为文件--> <appender name="file" class="ch.qos.logback.core.rolling.rollingfile自律委员会appender"> <file>logfile.log</file> <rollingpolicy class="ch.qos.logback.core.rolling.timebadrollingpolicy"> <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>
1.申明 logger 变量
private logger logger = loggerfactory.getlogger(loginlogdao.class);
2.在程序中调用日志
logger.debug(inrt_login_log_sql);
官方介绍网址:https://logback.qos.ch/demo.html
下面为官网介绍
logback-classic with two appenders: a consoleappender and a rollingfileappender. the rollingfileappender nds logging events to a file called logfile.log and will rollover the active file every minute. the old file will be renamed and compresd to a zip file. the consoleappender will output the logging requests to the console, and shorten the logger names to gain space on the console window, without loss of legibility. for example, ch.qos.logback.demo.prime.numbercruncherimpl will be abbreviated as c.q.l.d.prime.numbercruncherimpl.
输出结果如下
isdebugenabled true
2017-04-23 23:58:35,502 debug [http-nio-8080-exec-6] (login剪爱歌词logdao.java:32) – in可以为师矣rt into t_login_log(ur_id,ip,login_datetime) values(?,?,?)
2017-04-23 23:58:35,503 debug [http-nio-8080-exec-6] (jdbctemplate.java:869) – executing prepared sql update
2017-04-23 23:58:35,503 debug [http-nio-8080-exec-6] (jdbctemplate.java:616) – executing prepared sql statement [inrt into t_login_log(ur_id,ip,login_datetime) values(?,?,?)]
以上为个人经验,希望能给大家一个参考,也希望大家多多支持www.887551.com。
本文发布于:2023-04-04 07:39:57,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/9dfeb658b3c63397c59e024c1628917b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:解决引用slf4j中Logger.info只打印出文字没有数据的问题.doc
本文 PDF 下载地址:解决引用slf4j中Logger.info只打印出文字没有数据的问题.pdf
留言与评论(共有 0 条评论) |