问题
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.
- What is the difference between log4j, slf4j and logback?
- The SLF4J interfaces and their various adapters
If you use log4j2
then follow below texts.
- Set configuration. log4j2.xml
<Configuration status="WARN">
<Appenders>
...
</Appenders>
<Loggers>
<Root level="info">
... <AppenderRef> ...
</Root>
</Loggers>
</Configuration>
- 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