我的项目结构:
如您所见,我试图将 logback.xml 放在任何地方。
我想为根记录器设置信息日志级别。
logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<!-- Send logs to both console and file audit -->
<logger name="kafka_test" level="info">
<appender-ref ref="STDOUT" />
</logger>
</configuration>
我有以下代码:
public class Consumer {
private static final String name = "consumer_1";
private static Logger logger = LoggerFactory.getLogger(Consumer.class);
public static void main(String[] args) throws InterruptedException {
logger.debug("Consumer {} started", name);
...
它打印
17:51:45.096 [main] DEBUG kafka_test.Consumer - Consumer consumer_1 started
进入控制台。
我错了什么?
附言
我试图打印:
System.out.println(Consumer.class.getClassLoader().getResource("kafka_test/Consumer.class"));
它打印:
file:/D:/work/kafka_samples/out/production/classes/kafka_test/Consumer.class
我logback.xml
投入
D:\work\kafka_samples\out\production\classes\kafka_test
但它仍然不起作用
解决方案:
我已经logback.xml
投入
D:\work\kafka_samples\out\production\classes