How to disable strerr log output from FOP?

How to disable log output (usually sent to stderr) that FOP automatically generates when processing an FO file?

I tried to put the log4j.properties file in the classpath by changing the log level for org.apache.fop , but this did not work.

+7
java fop
source share
4 answers

Perhaps this is possible, but in version 1.1 you can create a class that implements EventListener . In processEvent you can simply ignore any messages you don't want to see.

From the 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; } } } 

Application:

 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()); 
+7
source share

I found a hint in the fop documentation: http://xmlgraphics.apache.org/fop/0.95/embedding.html#basic-logging : "We switched [...] to Jakarta Commons Logging", your log4j.properties is probably will not have any effect because they use community logging.

This works in my case:

 <logger name="org.apache.fop"> <level value="info" /> <appender-ref ref="logfile" /> <appender-ref ref="stdout" /> </logger> 

Check the public community management configuration to see if the discovery process can find log4j ( http://commons.apache.org/logging/guide.html#Configuration )

+1
source share

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); 
+1
source share

I don't know FOP, but you can always redirect STDERR to wherever you like, with code like:

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

Note: you do not need to redirect the file, PrintStream can accept any OutputStream .

0
source share

All Articles