<configuration debug="true"> in logback.xml.
statusListener(OnConsoleStatusListener) may help.
Or add the below to the source:
LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
HelloWorld.java
package log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;
public class HelloWorld {
public static void main(String[] args) {
LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
Logger logger = LoggerFactory.getLogger(HelloWorld.class);
logger.info("Hello World!");
}
}
logback.xml
<configuration debug="true">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>myApp.log</file>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyyMMdd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
logback.groovy
statusListener(OnConsoleStatusListener)
appender("FILE", FileAppender) {
file = "myApp.log"
encoder(PatternLayoutEncoder) {
pattern = "%date %level [%thread] %logger{10} [%file:%line] %msg%n"
}
}
appender("STDOUT", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = "%d{yyyyMMdd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
}
}
root(DEBUG, ["FILE","STDOUT"])
No comments:
Post a Comment