开发者

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 thi开发者_开发百科s 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);


Don't know FOP but you can always redirect the STDERR to where ever you like with code like the following:

File errDumpFile = new File("Path\to\a\File")
FileOutputStream fos = new FileOutputStream(errDumpFile);
PrintStream ps = new PrintStream(fos);
System.setErr(ps);

Note: you don't have to redirect to a file, the PrintStream can take any OutputStream.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜