如何在JavaMail IMAP连接期间临时禁用协议跟踪 [英] How to temporarily disable protocol tracing during a JavaMail IMAP connection

查看:96
本文介绍了如何在JavaMail IMAP连接期间临时禁用协议跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以指定在为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身份验证方法使用它来将您的凭据保留在日志文件之外.但是suspendTracingprotected,因此不能从常规用户代码中调用.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆