Spring Boot Logback - 如何删除 catalina.out 中的 DEBUG SMTP
Spring Boot Logback - how to remove DEBUG SMTP in catalina.out
我有一个 spring-boot 应用程序,它使用 Logback 进行日志记录。
我正在使用 RollingFileAppender
作为我的 DEBUG 和 ERROR 日志。
我的问题是我的 catalina.out
文件中有一些 DEBUG SMTP
和其他与邮件相关的日志。
我想将它们记录在我的 DEBUG 文件中。
下面是我的 logback 配置 (xml)。
登录XML:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATH" value="${logs.path.location}"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} -
%msg%n
</Pattern>
</layout>
</appender>
<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/iyotbihagay_debug.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_PATH}/archived/iyotbihagay_debug.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-ERROR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/iyotbihagay_error.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_PATH}/archived/iyotbihagay_error.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<logger name="ch.qos.logback" level="WARN" additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="org.springframework" level="INFO" additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="org.springframework.beans" level="WARN"
additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="java.sql" level="ERROR" additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<root level="ERROR">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
<appender-ref ref="FILE-ERROR" />
</root>
</configuration>
日志 (catalina.out):
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO ecomm-dev2
250-smtp.gmail.com at your service, [101.78.249.147]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.gmail.com, user=bilatbasa@gmail.com, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<tomcat@ecomm-bilatdev2>
250 2.1.0 OK w127-v6sm20332821pfd.112 - gsmtp
RCPT TO:<kataw.anan@gmail.com>
250 2.1.5 OK w127-v6sm20332821pfd.112 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: kataw.anan@gmail.com
DATA
354 Go ahead w127-v6sm20332821pfd.112 - gsmtp
Date: Tue, 16 Oct 2018 21:24:26 +0800 (HKT)
Reply-To: no-reply@iyotbihagay.com
To: kataw.anan@gmail.com
Message-ID: <544564802.2.1539696266428@ecomm-bilatdev2>
Subject: Test mail profile staging 0004
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_356550530.1539696264700"
------=_Part_0_356550530.1539696264700
Content-Type: multipart/related;
boundary="----=_Part_1_875170902.1539696264700"
------=_Part_1_875170902.1539696264700
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
知道为什么 DEBUG SMTP
和邮件相关的错误会出现在 catalina.out
中吗?
谢谢!
这些消息来自 class com.sun.mail.util.MailLogger
,看起来它们直接进入 PrintStream(可能 System.out,因此它们出现在 catalina,out 中)。
这是执行日志记录的代码:
public void log(Level level, String msg)
{
ifDebugOut(msg);
if (logger.isLoggable(level))
{
final StackTraceElement frame = inferCaller();
logger.logp(level, frame.getClassName(), frame.getMethodName(), msg);
}
private void ifDebugOut(String msg)
{
if (debug)
debugOut(msg);
}
private void debugOut(String msg)
{
if (prefix != null)
out.println(prefix + ": " + msg);
else
out.println(msg);
}
}
如果您不想看到它们,您应该能够设置 spring.mail
属性 以禁用邮件会话的调试日志记录。
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-email.html
我有一个 spring-boot 应用程序,它使用 Logback 进行日志记录。
我正在使用 RollingFileAppender
作为我的 DEBUG 和 ERROR 日志。
我的问题是我的 catalina.out
文件中有一些 DEBUG SMTP
和其他与邮件相关的日志。
我想将它们记录在我的 DEBUG 文件中。
下面是我的 logback 配置 (xml)。
登录XML:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATH" value="${logs.path.location}"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} -
%msg%n
</Pattern>
</layout>
</appender>
<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/iyotbihagay_debug.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_PATH}/archived/iyotbihagay_debug.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-ERROR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/iyotbihagay_error.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} - %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_PATH}/archived/iyotbihagay_error.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<logger name="ch.qos.logback" level="WARN" additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="org.springframework" level="INFO" additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="org.springframework.beans" level="WARN"
additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<logger name="java.sql" level="ERROR" additivity="false">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
</logger>
<root level="ERROR">
<if condition='property("profile").contains("dev")'>
<then>
<appender-ref ref="STDOUT" />
</then>
</if>
<appender-ref ref="FILE-AUDIT" />
<appender-ref ref="FILE-ERROR" />
</root>
</configuration>
日志 (catalina.out):
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO ecomm-dev2
250-smtp.gmail.com at your service, [101.78.249.147]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.gmail.com, user=bilatbasa@gmail.com, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<tomcat@ecomm-bilatdev2>
250 2.1.0 OK w127-v6sm20332821pfd.112 - gsmtp
RCPT TO:<kataw.anan@gmail.com>
250 2.1.5 OK w127-v6sm20332821pfd.112 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: kataw.anan@gmail.com
DATA
354 Go ahead w127-v6sm20332821pfd.112 - gsmtp
Date: Tue, 16 Oct 2018 21:24:26 +0800 (HKT)
Reply-To: no-reply@iyotbihagay.com
To: kataw.anan@gmail.com
Message-ID: <544564802.2.1539696266428@ecomm-bilatdev2>
Subject: Test mail profile staging 0004
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_356550530.1539696264700"
------=_Part_0_356550530.1539696264700
Content-Type: multipart/related;
boundary="----=_Part_1_875170902.1539696264700"
------=_Part_1_875170902.1539696264700
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
知道为什么 DEBUG SMTP
和邮件相关的错误会出现在 catalina.out
中吗?
谢谢!
这些消息来自 class com.sun.mail.util.MailLogger
,看起来它们直接进入 PrintStream(可能 System.out,因此它们出现在 catalina,out 中)。
这是执行日志记录的代码:
public void log(Level level, String msg)
{
ifDebugOut(msg);
if (logger.isLoggable(level))
{
final StackTraceElement frame = inferCaller();
logger.logp(level, frame.getClassName(), frame.getMethodName(), msg);
}
private void ifDebugOut(String msg)
{
if (debug)
debugOut(msg);
}
private void debugOut(String msg)
{
if (prefix != null)
out.println(prefix + ": " + msg);
else
out.println(msg);
}
}
如果您不想看到它们,您应该能够设置 spring.mail
属性 以禁用邮件会话的调试日志记录。
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-email.html