根据这个链接SLF4J Simple 可以通过simplelogger.properties
在运行时类路径上放置一个文件来配置。
一个例子simplelogger.properties
:
org.slf4j.simpleLogger.logFile=/home/myuser/.myapp/logs/myapp.log
org.slf4j.simpleLogger.defaultLogLevel=INFO
org.slf4j.simpleLogger.levelInBrackets=false
但是,如果我希望我的应用程序定义它自己的环境变量,比如 ,MYAPP_HOME
并将其设置为/home/myuser/.myapp/logs
. 然后我将如何MYAPP_HOME
从内部引用变量simplelogger.properties
?这甚至可能吗?
例如,我可以这样做:
org.slf4j.simpleLogger.logFile=${MYAPP_HOME}/logs/myapp.log
org.slf4j.simpleLogger.defaultLogLevel=INFO
org.slf4j.simpleLogger.levelInBrackets=false
注意:以上不起作用并导致以下异常:
Could not open [${MYAPP_HOME}/logs/myapp.log]. Defaulting to System.err
Reported exception:
java.io.FileNotFoundException: ${MYAPP_HOME}/logs/myapp.log (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
at java.io.FileOutputStream.<init>(FileOutputStream.java:99)
at org.slf4j.impl.SimpleLogger.computeTargetStream(SimpleLogger.java:224)
at org.slf4j.impl.SimpleLogger.init(SimpleLogger.java:205)
at org.slf4j.impl.SimpleLogger.<init>(SimpleLogger.java:268)
at org.slf4j.impl.SimpleLoggerFactory.getLogger(SimpleLoggerFactory.java:57)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
... rest of stack trace omitted for brevity
提前致谢!