如何将 javax.mail.Session setDebugOut 重定向到 log4j 记录器?
是否可以仅将 mailSession 调试重定向到记录器?
我的意思是,有类似的解决方案
将所有标准输出重新分配给 log4j
--System.setOut(new Log4jStream())
最好的问候
最佳答案
Apache Commons Exec库包含有用的类 LogOutputStream ,您可以将其用于此确切目的:
LogOutputStream losStdOut = new LogOutputStream() {
@Override
protected void processLine(String line, int level) {
cat.debug(line);
}
};
Session session = Session.getDefaultInstance(new Properties(), null);
session.setDebugOut(new PrintStream(losStdOut));
cat 显然是 log4j Category/Appender。
关于java - 如何将 javax.mail.Session setDebugOut 重定向到 log4j 记录器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2118370/