如何在命令行上配置log4j属性文件?

时间:2014-09-12 23:06:35

标签: log4j sbt

我使用sbt编译项目,并使用slf4j-log4j进行日志记录。我的log4j.properties文件不在类路径中 - 它位于conf/log4j.properties

我想在sbt run的命令行上运行我的项目,并配置log4j文件。我已经尝试了

sbt "run -Dlog4j.configuration=conf/log4j.properties"
sbt "run -Dlog4j.configuration=file:///conf/log4j.properties"

和其他一些变体,总是给我同样的警告,

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

1 个答案:

答案 0 :(得分:3)

答案取决于您如何在fork设置控制的情况下运行您的应用程序。

> help fork
If true, forks a new JVM when running.  If false, runs in the same JVM as the build.

fork设置为false,您必须使用-DSBT_OPTS传递给sbt进程本身,以便有效地设置整个的Java属性建立。

fork设置为true后,您可以使用javaOptions

> help javaOptions
Options passed to a new JVM when forking.
相关问题