Where does slf4j-jdk14 get logging configurations from?

守給你的承諾、 提交于 2020-05-16 05:53:42

问题


Where does slf4j-jdk14 get configurations from? I am using

    compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.8.0-alpha2'

and importing

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

In my java file my code is as below:

Logger logger=LoggerFactory.getLogger(AppTest.class);
logger.info("This is my login!!");

I am getting logs genereated but dont know where it is taking properties from. I want to disable Info logs from my property file as well as put those logs to file. I dont have any property file or log4j xml file.


回答1:


slf4j is Simple Logging Facade for Java.

There is a reason you can't set configuration. please, visit this link : When should SLF4J be used?

so it can only print on standard output like console. If you want to log and save it on external file then you'd better use logging framework like log4j2, logback, If you want to know about difference log4j2 and other logging framework then please visit below links.

  1. What is the difference between log4j, slf4j and logback?
  2. The SLF4J interfaces and their various adapters

If you use log4j2 then follow below texts.

  1. Set configuration. log4j2.xml
<Configuration status="WARN">
  <Appenders>
    ...
  </Appenders>
  <Loggers>
    <Root level="info">
        ... <AppenderRef> ...
    </Root>
  </Loggers>
</Configuration>
  1. Change Log level to edit Root level For example, edit level optioin from<Root level="info"> to <Root level="error">



回答2:


Using logback instead of slf4j-jdk14 solved my prob

compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'



来源:https://stackoverflow.com/questions/61578445/where-does-slf4j-jdk14-get-logging-configurations-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!