英文:
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}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论