<small id='uERtX'></small><noframes id='uERtX'>

<i id='uERtX'><tr id='uERtX'><dt id='uERtX'><q id='uERtX'><span id='uERtX'><b id='uERtX'><form id='uERtX'><ins id='uERtX'></ins><ul id='uERtX'></ul><sub id='uERtX'></sub></form><legend id='uERtX'></legend><bdo id='uERtX'><pre id='uERtX'><center id='uERtX'></center></pre></bdo></b><th id='uERtX'></th></span></q></dt></tr></i><div id='uERtX'><tfoot id='uERtX'></tfoot><dl id='uERtX'><fieldset id='uERtX'></fieldset></dl></div>
  • <tfoot id='uERtX'></tfoot>

    1. <legend id='uERtX'><style id='uERtX'><dir id='uERtX'><q id='uERtX'></q></dir></style></legend>

        • <bdo id='uERtX'></bdo><ul id='uERtX'></ul>

        从 logback 配置文件中读取环境变量

        Read environment variables from logback configuration file(从 logback 配置文件中读取环境变量)
        • <bdo id='WKlzP'></bdo><ul id='WKlzP'></ul>
              <tbody id='WKlzP'></tbody>

                <small id='WKlzP'></small><noframes id='WKlzP'>

                <i id='WKlzP'><tr id='WKlzP'><dt id='WKlzP'><q id='WKlzP'><span id='WKlzP'><b id='WKlzP'><form id='WKlzP'><ins id='WKlzP'></ins><ul id='WKlzP'></ul><sub id='WKlzP'></sub></form><legend id='WKlzP'></legend><bdo id='WKlzP'><pre id='WKlzP'><center id='WKlzP'></center></pre></bdo></b><th id='WKlzP'></th></span></q></dt></tr></i><div id='WKlzP'><tfoot id='WKlzP'></tfoot><dl id='WKlzP'><fieldset id='WKlzP'></fieldset></dl></div>
                <tfoot id='WKlzP'></tfoot><legend id='WKlzP'><style id='WKlzP'><dir id='WKlzP'><q id='WKlzP'></q></dir></style></legend>
                  本文介绍了从 logback 配置文件中读取环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这个 logback.xml 文件:

                  I have this logback.xml file:

                  <configuration debug="true" scan="true" scanPeriod="60 seconds">
                  
                    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                      <layout class="ch.qos.logback.classic.PatternLayout">
                        <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
                      </layout>
                    </appender>
                  
                    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
                      <File>${MY_HOME}/logs/mylog.log</File>
                  
                      <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                        <FileNamePattern>logs/my.%d{yyyy-MM-dd}.log</FileNamePattern>
                        <MaxHistory>30</MaxHistory>
                      </rollingPolicy>
                  
                      <layout class="ch.qos.logback.classic.PatternLayout">
                        <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level - %msg%n</Pattern>
                      </layout>
                  
                    </appender> 
                  
                    <root level="TRACE">
                      <appender-ref ref="FILE"/>
                    </root>
                  
                  </configuration>
                  

                  ${MY_HOME} 是一个已定义的系统变量(linux 上的 echo $MY_HOME 显示正确的路径).

                  And ${MY_HOME} is a defined system variable (echo $MY_HOME on linux shows the correct path).

                  问题是 logback 似乎没有正确读取它,它将日志存储在 MY_HOME_IS_UNDEFINED/logs/my.log

                  The thing is that logback doesnt seem to read it properly, it stores the logs under MY_HOME_IS_UNDEFINED/logs/my.log

                  我做错了什么?非常感谢!

                  What am I doing wrong? Thanks a lot!

                  我犯了一个错误,将 OSC_HOME 放在我真正指的是 MY_HOME 的位置.对此感到抱歉

                  I made a mistake and put OSC_HOME where I really meant MY_HOME. Sorry about that

                  推荐答案

                  与其他人所说的相反,logback 文档明确声明在替换期间,首先在本地范围内查找属性,然后在上下文范围内查找,然后在系统属性范围内查找第三个,在操作系统环境中查找第四个也是最后一个".所以如果该属性是在环境中定义的,logback 就会找到它.

                  Contrary to what the others have said, the logback documentation explicitly states that "During substitution, properties are looked up in the local scope first, in the context scope second, in the system properties scope third, and in the OS environment fourth and last". So if the property is defined in the environment, logback will find it.

                  我在 Eclipse 中运行我的项目时遇到了同样的问题.如果这是您遇到的问题,可以通过转到 Run Configurations -> Environment 并将 MY_HOME 添加到环境变量来解决.

                  I was having the same issue when running my project in Eclipse. If that's the issue you're having, it can be fixed by going to Run Configurations -> Environment and adding MY_HOME to the environment variables.

                  不确定为什么默认情况下它不加载本机环境.甚至还有一个名为将环境附加到本机环境"的选项,这似乎对我没有任何影响.

                  Not really sure why it isn't loading the native environment by default. There's even an option called "Append environment to native environment" which doesn't seem to have any effect for me.

                  这篇关于从 logback 配置文件中读取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                  Java System Environment Variable(Java 系统环境变量)
                  Java -classpath option(Java -classpath 选项)
                  Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                  Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                  Issue with JAVA_HOME(JAVA_HOME 的问题)

                    <small id='qovEh'></small><noframes id='qovEh'>

                    <tfoot id='qovEh'></tfoot>

                    • <legend id='qovEh'><style id='qovEh'><dir id='qovEh'><q id='qovEh'></q></dir></style></legend>

                        • <bdo id='qovEh'></bdo><ul id='qovEh'></ul>
                        • <i id='qovEh'><tr id='qovEh'><dt id='qovEh'><q id='qovEh'><span id='qovEh'><b id='qovEh'><form id='qovEh'><ins id='qovEh'></ins><ul id='qovEh'></ul><sub id='qovEh'></sub></form><legend id='qovEh'></legend><bdo id='qovEh'><pre id='qovEh'><center id='qovEh'></center></pre></bdo></b><th id='qovEh'></th></span></q></dt></tr></i><div id='qovEh'><tfoot id='qovEh'></tfoot><dl id='qovEh'><fieldset id='qovEh'></fieldset></dl></div>
                            <tbody id='qovEh'></tbody>