简体   繁体   English

排除 Spring Boot 日志

[英]Exclude Spring Boot logs

I'm trying to configure my log4j2 logger to write logs INFO to file, but there are 20+ logs from Spring Boot, which i don't need.我正在尝试配置我的log4j2记录器以将日志信息写入文件,但是 Spring Boot 中有 20 多个日志,我不需要这些日志。 My pom.xml我的pom.xml

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
    <exclusions>
        <exclusion>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-to-slf4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.7</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.7</version>
</dependency>

log4j.properties

log4j.rootLogger=INFO, file

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=mylogs.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n

MailService.class

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MailService {
    private static final Logger logger = LoggerFactory.getLogger(MailService.class);

    void sendMail() {
            logger.trace("Email sent!!");
            logger.debug("Email sent!!");
            logger.info("Email sent!!");
            logger.warn("Email sent!!");
    }
}

Try to add in your applcation.properties :尝试添加您的applcation.properties

logging.level.org.springframework=OFF

logging.level.root=OFF

But watch out, I'm not sure it's the best solution.但请注意,我不确定这是最佳解决方案。

You need to add properties to disable logs for specific module.您需要添加属性以禁用特定模块的日志。 log4j2.properties should contain below prop to hide glassfish logs. log4j2.properties应包含以下道具以隐藏 glassfish 日志。 You can make appropriate changes to match your requirement.您可以进行适当的更改以符合您的要求。

logger.glassfish.name = org.glassfish
logger.glassfish.level = off

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

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