我想使用log4j的1.2.9與4.0.1春季和JBoss 7.1,但每次我登錄控制檯的信息,但創建空文件...log4j的彈簧創建空文件
log4j的。屬性
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\log\\loggingFile.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
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{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=INFO, file, stdout
的web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
簡單測試控制器
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
@ManagedBean(name="MyController")
public class MyController {
static final Logger logger = Logger.getLogger(MyController.class);
public String test() {
BasicConfigurator.configure();
logger.debug(LoginController.class);
logger.info("Info.. ");
logger.error("Error..");
logger.fatal("Fatal");
return null;
}}
我不知道關於Spring配置監聽器,但log4j系統屬性來定義配置文件資源ist'log4j.configuration'而不是'log4jConfigLocation'(https://logging.apache.org/log4j/1.2/manual.html#defaultInit) – FrVaBe
當我將其更改爲log4j.configuration該文件沒有創建 – elpazio