这是我的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%msg%n"/>
</Console>
<File name="MyFile" fileName="file.log" immediateFlush="false" append="false">
<PatternLayout pattern="%msg%n"/>
</File>
</Appenders>
<Loggers>
<Logger level="debug" includeLocation="true">
<AppenderRef ref="MyFile"/>
</Logger>
<Root level="info">
<AppenderRef ref="Console"></AppenderRef>
</Root>
</Loggers>
</Configuration>
如何更改:
爪哇:
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) {
logger.info("info");
logger.debug("debug");
}
问题是文件已创建,但它是空的......
谢谢
答案 0 :(得分:0)
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%msg%n"/>
</Console>
<File name="MyFile" fileName="file.log" immediateFlush="true" append="false">
<PatternLayout pattern="%msg%n"/>
</File>
</Appenders>
<Loggers>
<Logger name="JavaPhit.Log.File" level="DEBUG" includeLocation="true">
<AppenderRef ref="MyFile"/>
</Logger>
<Root level="DEBUG">
<AppenderRef ref="Console" level="info"></AppenderRef>
<AppenderRef ref="MyFile" level="debug" />
</Root>
</Loggers>
</Configuration>