log4j.properties适用于eclipse,但会导致intellij出错

log4j.properties适用于eclipse,但会导致intellij出错,eclipse,intellij-idea,log4j,Eclipse,Intellij Idea,Log4j,这是我的log4j文件: log4j.rootLogger=INFO, A1, ERROR, A1 #Direct log messages to a log file log4j.appender.A1.File=/place/logs/applog/dashboard.log log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM

这是我的log4j文件:

log4j.rootLogger=INFO, A1, ERROR, A1
#Direct log messages to a log file
log4j.appender.A1.File=/place/logs/applog/dashboard.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c:%L %t- %m%n
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.logger.org.springframework.cache=DEBUG
log4j.logger.net.sf.ehcache=TRACE
以下是intellij抛出的错误,但不是eclipse

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/Cellar/tomcat/8.0.26/libexec/webapps/ROOT/WEB-INF/lib/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/tomcat/8.0.26/libexec/webapps/ROOT/WEB-INF/lib/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:ERROR Could not find value for key log4j.appender.A1
log4j:ERROR Could not instantiate appender named "A1".
log4j:ERROR Could not find value for key log4j.appender.ERROR
log4j:ERROR Could not instantiate appender named "ERROR".
log4j:ERROR Could not find value for key log4j.appender.A1
log4j:ERROR Could not instantiate appender named "A1".
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我对log4j不太熟悉,所以像我5岁一样向我解释一下。谢谢

我愚弄log4j配置已经有一段时间了,但在rootlogger行中,为什么要定义A1两次?我认为该地产的模式是:

默认日志级别,适用于根目录的附加程序列表

因此,在你的情况下:

rootLogger = INFO, console, A1

自从我愚弄log4j配置已经有一段时间了,但是在rootlogger行中,为什么要定义A1两次呢?我认为该地产的模式是:

默认日志级别,适用于根目录的附加程序列表

因此,在你的情况下:

rootLogger = INFO, console, A1

使用IntelliJ IDEA第1步:在主方法中放在第一行

BasicConfigurator.configure();
步骤2:转到帮助>编辑自定义属性并插入代码

log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

使用IntelliJ IDEA第1步:在主方法中放在第一行

BasicConfigurator.configure();
步骤2:转到帮助>编辑自定义属性并插入代码

log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

实际上,这似乎解决了问题。我不认为IDE对这一点有任何影响。很好的交易-是的,我不确定这是否是IDE会产生影响的问题。这似乎实际上解决了它。我不认为IDE对这一点有任何影响。很好的交易-是的,我不确定这是否是IDE会产生影响的问题。