This logback.xml is logging to file but fails to log to console? I am hoping someone can spot the configuration error in this config? Here is my basic logger config:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
public static Logger logger = LoggerFactory.getLogger( "JUnit" );
...
logger.info("This comment fails to show in console but it shows in log file");
And here is the logback.xml :
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>junitOut.log</file>
<append>false</append>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4r %-5level %logger{35}: %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
<!-- We want error logging from this logger to go to an extra appender
It still inherits CONSOLE STDOUT from the root logger -->
<logger name="junitOut" level="INFO">
<appender-ref ref="STDOUT" />
</logger>
</configuration>
debug=true to enable debugging of the logback setup. Unfortunately, there is no way to enable debugging via a System property. You have to use <configuration debug="true"> in the logback. xml .
In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.
You don't explicitly define a logger named "JUnit", so the logging message will go to root logger directly. The root logger has just one appender, i.e. "FILE", so the logging message will be written to the file only. You can add the "STDOUT" appender to the root logger in your case:
<root level="DEBUG">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With