gpt4 book ai didi

java - 如何禁用 FOP 的 strerr 日志记录输出?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:16:51 25 4
gpt4 key购买 nike

如何禁用 FOP 在处理 FO 文件时自动生成的日志记录输出(通常发送到 stderr)?

我试过在类路径中放置一个 log4j.properties 文件,更改 org.apache.fop 的日志级别,但这没有用。

最佳答案

这可能晚了,但在 1.1 版中,您可以创建一个实现 EventListener 的类。在 processEvent 中,您可以简单地忽略任何您不想看到的消息。

来自 FOP Docs :

import org.apache.fop.events.Event;
import org.apache.fop.events.EventFormatter;
import org.apache.fop.events.EventListener;
import org.apache.fop.events.model.EventSeverity;

/** A simple event listener that writes the events to stdout and stderr. */
public class SysOutEventListener implements EventListener {

/** {@inheritDoc} */
public void processEvent(Event event) {
String msg = EventFormatter.format(event);
EventSeverity severity = event.getSeverity();
if (severity == EventSeverity.INFO) {
System.out.println("[INFO ] " + msg);
} else if (severity == EventSeverity.WARN) {
System.out.println("[WARN ] " + msg);
} else if (severity == EventSeverity.ERROR) {
System.err.println("[ERROR] " + msg);
} else if (severity == EventSeverity.FATAL) {
System.err.println("[FATAL] " + msg);
} else {
assert false;
}
}
}

用法:

StreamSource strm = new StreamSource(new File(fo));
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(new File(pdfName)));
Fop fop = _fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.__Fields.MIME_PDF, outStream);
FOUserAgent foUserAgent = fop.getUserAgent();
foUserAgent.getEventBroadcaster().addEventListener(new SysOutEventListener());

关于java - 如何禁用 FOP 的 strerr 日志记录输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2553199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com