0

我正在尝试使用 Spring。Spring的一个依赖是

所以我已经添加commons-logging-1.1.1.jar到我的构建路径中。这一切都很好。我得到这样的东西:

Feb 28, 2013 2:40:39 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c63a8af: startup date [Thu Feb 28 14:40:39 GMT 2013]; root of context hierarchy

这一切都很好,但我不想把它打印到我的标准输出,我希望它被发送到一个文件中。

目录结构:

project
  src
    com.myproject.classes
    myspring.xml
    log4j.properties
  test
    com.myproject.classes
  logs
    myproject.log

所以我想将所有日志从标准输出重定向到日志文件。这可能与春天?

我使用了这里的属性文件:http ://www.tutorialspoint.com/spring/logging_with_log4j.htm ,我从那里得到了我的 Spring 示例。但这似乎没有任何区别。我也在那里添加了一些垃圾,看看是否有任何异常被抛出,但什么也没有。我尝试将文件移动到不同的目录,但它仍然不起作用。

这里是:

# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=logs/myproject.log

# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true

# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug

# Set the append to false, overwrite
log4j.appender.FILE.Append=false

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

有人有什么想法吗?

提前致谢。

4