简体   繁体   English

如何在Tomcat中设置服务器日志位置

[英]How to set the server-log location in Tomcat

I recently started working in a Spring boot application. 我最近开始在Spring启动应用程序中工作。 The application uses spring-logback for logging implementation. 该应用程序使用spring-logback进行日志记录实现。

The application is bundled as a war in different environments. 该应用程序在不同的环境中捆绑在一起成为一场战争。 However, the location of writing logs is different in each environment and is mentioned in a logging.properties file. 但是,写入日志的位置在每种环境中都不同,并且在logging.properties文件中提到了该位置。

Therefore, I currently have to change the location before preparing the war every time. 因此,我目前必须每次准备战争之前都要更改位置。

How can I set the path of the logs in the Tomcat configuration so that the path is auto-picked for an environment. 如何在Tomcat配置中设置日志的路径,以便为环境自动选择该路径。

Currently mu logback appender looks like this: 当前,mu logback附加器如下所示:

<appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${logging.file}</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

        <!-- daily rollover -->
        <fileNamePattern>${logging.file}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>${log.file.size}</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
        <maxHistory>${log.file.history}</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>${logging.pattern.file}</pattern>
    </encoder>
</appender>

All the properties here are picked from logging.properties file inside the src/main/resources 此处的所有属性均从src/main/resources logging.properties文件中选取

spring-boot provides several logging.* settings that can be applied in application.properties, like: spring-boot提供了几个logging.*设置,可以在application.properties中应用它们,例如:

logging.level.=DEBUG
logging.file=myfile.log
logging.path=d:/logs/  

If you set logging.path, Spring Boot writes spring.log to the specified directory. 如果设置logging.path,Spring Boot会将spring.log写入指定目录。 Names can be an exact location or relative to the current directory. 名称可以是确切位置,也可以是相对于当前目录的位置。

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

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