How would I disable the logging output (usually sent to stderr) that FOP automatically generates when processing an FO file?
I've tried putting a log4j.properties
file in the classpath, changing the log-level for org.apache.fop
but this hasn't worked.
This maybe late, but in version 1.1 your can create a class that implements EventListener
. In processEvent
you can simply ignore any messages you don't want to see.
From 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;
}
}
}
Usage:
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());
I found a hint in the fop documentation: http://xmlgraphics.apache.org/fop/0.95/embedding.html#basic-logging saying "We've switched [...] to Jakarta Commons Logging". Your log4j.properties
will probably have no effect, because they are using commons logging.
This works in my case:
<logger name="org.apache.fop">
<level value="info" />
<appender-ref ref="logfile" />
<appender-ref ref="stdout" />
</logger>
Check your commons logging configuration, whether the discovery process can find log4j ( http://commons.apache.org/logging/guide.html#Configuration )
You can do something like this:
org.apache.commons.logging.impl.Log4JLogger log = (org.apache.commons.logging.impl.Log4JLogger) LogFactory.getLog("org.apache.fop");
log.getLogger().setLevel(org.apache.log4j.Level.FATAL);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With