如何在JavaMail IMAP连接期间临时禁用协议跟踪 [英] How to temporarily disable protocol tracing during a JavaMail IMAP connection
问题描述
您可以指定在为Session
设置Properties
时(通过将"mail.debug"
属性设置为"true"
)还是通过调用
You can specify whether JavaMail emits a protocol-level trace either when setting the Properties
for your Session
(by setting the "mail.debug"
property to "true"
) or by calling Session.setDebug
before you do the store connect.
但是,当实例化Protocol
对象时,它将创建一个协议" TraceLogger
,该协议在协议对象的生存期内一直存在.这似乎意味着一旦开始使用它就无法临时禁用连接上的协议级调试日志记录.
However, when the Protocol
object gets instantiated, it creates a "protocol" TraceLogger
that persists for the lifetime of the protocol object. Which appears to mean that you can't temporarily disable protocol-level debug logging on a connection once you start using it.
有 是Protocol.suspendTracing
方法.它确实允许您暂时关闭协议跟踪输出.一堆IMAP身份验证方法使用它来将您的凭据保留在日志文件之外.但是suspendTracing
是protected
,因此不能从常规用户代码中调用.
There is a Protocol.suspendTracing
method. And it does allow you to temporarily turn off protocol trace output. A bunch of the IMAP auth methods use it to keep your credentials out of the logfile. But suspendTracing
is protected
, so it's not callable from regular user code.
还有另一种方法可以暂时关闭IMAP协议跟踪吗? (我宁愿暂时只关闭traceInput
日志记录,但可以禁用所有日志记录.)是否需要编写和注册整个Protocol子类,以便可以访问Protocol.suspendTracing
?
Is there another way to temporarily turn off IMAP protocol tracing? (I'd prefer temporarily turning off just the traceInput
logging, but I'm fine with disabling all logging.) Do I need to write and register a whole Protocol subclass so I can get access to Protocol.suspendTracing
?
推荐答案
您可以使用Session.setDebugOut设置自己的流并从那里控制它.
You could use Session.setDebugOut to set your own stream and control it from there.
如果您使用的是java.util.logging,则可以随时更改日志记录级别.
If you're using java.util.logging, you can change the logging level at any time.
这篇关于如何在JavaMail IMAP连接期间临时禁用协议跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!