log4j - 访问环境变量
我将以下环境变量放入 CATALINA.BAT 中,
set "APACHE_WEB_DIRECTORY=C:/wamp/www/DuInvestColombo"
我尝试按如下方式访问该变量,
apacheWebDirectory=${APACHE_WEB_DIRECTORY}
但它不起作用,日志未写入该目录
log4j.appender.applicationLogsFileAppender.File=${apacheWebDirectory}/ApplicationLogs.log
将此环境变量获取到 log4j 的正确方法是什么
I put the following environment variable in the CATALINA.BAT
set "APACHE_WEB_DIRECTORY=C:/wamp/www/DuInvestColombo"
i tried to access the variable as follow
apacheWebDirectory=${APACHE_WEB_DIRECTORY}
but it didn't work, logs did not writtent to the directory
log4j.appender.applicationLogsFileAppender.File=${apacheWebDirectory}/ApplicationLogs.log
what is the correct way to get this environment variable to log4j
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
log4j 中的 PropertyConfigurator 使用 OptionConverter 替换属性文件中的 ${name} 变量。但转换的值取自系统属性,而不是环境。
您在哪里尝试以“apacheWebDir =“{APACHE_WEB_DIR}”访问变量?.bat 文件仅知道 % 的变量替换
当您使用 .bat 文件时,启动 java 程序的调用必须包括:
The PropertyConfigurator in log4j used the OptionConverter to replace ${name} variables in the property file. But the value for the conversion is taken from the system-properties, not from the environment.
Where did you try to access the variable as "apacheWebDir="{APACHE_WEB_DIR}"? The .bat file only knows variable substitution by %
As you are using a .bat file, your call to start the java program has to include: