[英]Log4j: how to compose config?
I added Log4j2 to the project, and added config.我将 Log4j2 添加到项目中,并添加了配置。
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\logging.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Than, I log code like here:比,我在这里记录代码:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
...
final static Logger logger = LogManager.getLogger(AbstractEditor.class);
...
logger.info("updated: " + entity);
logger.debug("==> debug");
logger.info("==> info");
logger.warn("==> warn");
logger.error("==> error");
logger.fatal("==> fatal");
logger.trace("==> trace");
As I understand, all logs with level higher than DEBUG must be written to console and file.据我了解,所有级别高于 DEBUG 的日志都必须写入控制台和文件。 But only this has been printed into console:
但只有这个被打印到控制台:
15:08:52.285 [http-nio-8080-exec-1] ERROR ru.example.AbstractEditor - ==> error
15:08:52.292 [http-nio-8080-exec-1] FATAL ru.example.AbstractEditor - ==> fatal
I see this strings not matches my config.我看到这个字符串与我的配置不匹配。 And they are not witten into file.
并且他们没有被写入文件。 When I added this config, all logs disappeared from console, excluding this 2 strings.
当我添加这个配置时,所有日志都从控制台消失了,不包括这 2 个字符串。
Please help to write config to see all logs with level from DEBUG on console and file.请帮助编写配置以查看控制台和文件上调试级别的所有日志。
You are programmatically using Log4j 2 but using the configuration format of Log4j 1. Log4j 2 is ignoring your configuration and using the default.您以编程方式使用 Log4j 2,但使用 Log4j 1 的配置格式。 Log4j 2 忽略您的配置并使用默认值。 You have 2 choices.
你有2个选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.