【问题标题】:Spring boot application LoggingSpring Boot 应用程序日志记录
【发布时间】:2017-12-06 18:04:17
【问题描述】:

我们有一个 spring boot 应用程序,在 application.properties 中我们将日志文件位置设置为写入 /var/log/onbase.log

但是每当服务器启动时,就会有一个额外的日志写入 var/onbaseAPP.log(这个日志正在填满盒子上的内存,服务器会挂掉)

我们在代码中没有任何内容来创建 onbaseApp.log,不确定它是如何创建的

请帮忙。提前致谢。

【问题讨论】:

  • logback 还是 log4j ?

标签: spring spring-boot logging


【解决方案1】:

如果您使用 Log4j 或 Log4j2,则需要更改您的依赖项以包含您要使用的日志记录实现的适当启动器并排除 Logback。

对于 Maven 构建,您可以通过排除由根启动器依赖项传递解析的默认日志记录启动器来排除 Logback:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

在 Gradle 中,将排除项放在配置部分下是最简单的:

configurations {
    all*.exclude group:'org.springframework.boot',
    module:'spring-boot-starter-logging'
}

排除默认的日志记录启动器后,您现在可以包含日志记录的启动器 你宁愿使用的实现。使用 Maven 构建,您可以像这样添加 Log4j:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
</dependency>

在 Gradle 构建中,您可以像这样添加 Log4j:

compile("org.springframework.boot:spring-boot-starter-log4j")

你的 application.properties 像这样:

logging.path=/var/log/
logging.file=onbase.log
#logging.level.root=WARN
#logging.level.root.org.springframework.security=DEBUG

资料来源:Spring Boot 实战 Craig Walls

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-02
    • 2016-05-30
    • 2019-05-11
    • 1970-01-01
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    相关资源
    最近更新 更多