在Java中设置log4j的默认路径。

huangapple go评论79阅读模式
英文:

Set log4j default path in java

问题

我想为我的应用程序设置默认文件路径,以防未定义${custom.log.path},或以任何方式无法创建该路径,那么日志应该生成在默认位置。

我正在使用Spring应用程序,不确定如何配置默认文件路径。

log4j.properties:

# 根记录器选项
log4j.rootLogger=DEBUG, file

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${custom.log.path}/Application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n
英文:

I want to set default file path for my application, in case ${custom.log.path} is not defined or by any means can't be created than logs should be generated at default location.

I am using spring application, not sure how to configure the default file path.

log4j.properties :

# Root logger option
log4j.rootLogger=DEBUG, file

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${custom.log.path}/Application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n

答案1

得分: 1

以下是翻译好的内容:

查看这个主题和答案:https://stackoverflow.com/questions/2513484/is-there-a-way-to-specify-a-default-property-value-in-spring-xml

Spring Framework支持以下语法:
${my.variable:defaultValue}

英文:

Check this topic and answers: https://stackoverflow.com/questions/2513484/is-there-a-way-to-specify-a-default-property-value-in-spring-xml

Spring Framework supports the following syntax:
${my.variable:defaultValue}

huangapple
  • 本文由 发表于 2020年10月20日 14:35:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/64439693.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定