简体   繁体   English

classpath中的logback.xml与logging.config环境参数spring boot一起执行

[英]logback.xml in classpath getting executed along with logging.config Environment argument spring boot

I have a spring boot project(version 1.3.6) and i have added logback.xml to the project. 我有一个春季启动项目(版本1.3.6),并且我已将logback.xml添加到该项目中。 On creating an executable jar, the logback.xml is getting included in the jar and also working as expected. 创建可执行jar时,logback.xml将包含在jar中,并且也可以按预期工作。 As the development is done on a windows system, so logback.xml in classpath adds the logs to file at path F:/application/logs/abc.log. 由于开发是在Windows系统上完成的,因此classpath中的logback.xml将日志添加到路径F:/application/logs/abc.log的文件中。

But on deployment of the jar on unix server, i want to provide logback.xml configuration from external file with a different path for logging file say (/opt/logs/abc.log) . 但是在将jar部署到unix服务器上时,我想从外部文件提供logback.xml配置,并使用不同的路径记录日志文件(/opt/logs/abc.log) I used -Dlogging.config argument while executing my jar file to provide the external logback.xml configuration file as below. 我在执行jar文件时使用-Dlogging.config参数,以提供如下所示的外部logback.xml配置文件。

java -Dlogging.config=/path/to/logback.xml -jar ABC.jar

On running the above command, the logs are getting created successfully at /opt/logs/abc.log as per the external file configuration but the issue is that F:/application/logs/abc.log directory structure also gets created with a 0 byte file though no logging is being done in this. 在运行上述命令时,根据外部文件配置,已在/opt/logs/abc.log中成功创建了日志,但问题是F:/application/logs/abc.log目录结构也被创建为0字节文件,尽管此操作未进行任何日志记录。

So if i am running my application from say /local directory on the server, then the below directories are getting created. 因此,如果我从服务器上的/ local目录运行应用程序,则将创建以下目录。

/local/F:/application/logs/abc.log

My question is how can we avoid the classpath log file directory structure( /local/F:/application/logs/abc.log ) from getting created if external logback.xml configuration is used. 我的问题是,如果使用外部logback.xml配置,如何避免创建类路径日志文件目录结构( /local/F:/application/logs/abc.log )。

My logback.xml is below. 我的logback.xml在下面。

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<appender name="ROLLINGFILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>F:/FRF/logs/iqcx-ticketing.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>F:/FRF/logs/iqcx-ticketing-%d{yyyy-MM}.%i.zip
        </fileNamePattern>
        <maxHistory>10</maxHistory>
        <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>20MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder>
        <pattern>%date{ISO8601} [%thread] - %-5level %logger %X - %msg%n
        </pattern>
    </encoder>
</appender>
<root>
    <appender-ref ref="ROLLINGFILE" />
</root>
<logger name="iqcxLogger" level="info">
    <appender-ref ref="ROLLINGFILE" />
</logger>
<logger name="org.springframework" level="info" additivity="false">
    <appender-ref ref="ROLLINGFILE" />
</logger>
<logger name="org.mybatis.spring" level="info" additivity="false">
    <appender-ref ref="ROLLINGFILE" />
</logger>
<logger name="org.hibernate.validator" level="info" additivity="false">
    <appender-ref ref="ROLLINGFILE" />
</logger>
<logger name="org.apache.commons.beanutils" level="info" additivity="false">
    <appender-ref ref="ROLLINGFILE" />
</logger>

</configuration>

由于logback.xml在类路径F中:除非您通过在命令行中添加-Dlogging.file=/opt/logs/abc.log参数来覆盖logging.file属性,否则将创建/application/logs/abc.log。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM