Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable the strerr logging output from FOP?

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.

like image 511
Phillip B Oldham Avatar asked Mar 31 '10 13:03

Phillip B Oldham


3 Answers

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());
like image 122
PhillyNJ Avatar answered Oct 28 '22 11:10

PhillyNJ


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 )

like image 33
slartidan Avatar answered Oct 28 '22 12:10

slartidan


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);
like image 1
joycollector Avatar answered Oct 28 '22 11:10

joycollector