2010-03-31 35 views

Trả lời

0

Không biết FOP nhưng bạn luôn có thể chuyển hướng các thiết bị lỗi chuẩn để nơi nào bạn thích với mã như sau:

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

Lưu ý: bạn không cần phải chuyển hướng đến một tập tin, các PrintStream thể lấy bất kỳ OutputStream nào.

1

Tôi tìm thấy gợi ý trong tài liệu fop: http://xmlgraphics.apache.org/fop/0.95/embedding.html#basic-logging nói "Chúng tôi đã chuyển [...] thành Jakarta Commons Logging". log4j.properties của bạn có thể sẽ không có hiệu lực, bởi vì họ đang sử dụng đăng nhập commons.

này hoạt động trong trường hợp của tôi:

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

Kiểm tra commons bạn đăng nhập cấu hình, cho dù quá trình khám phá có thể tìm thấy log4j ( http://commons.apache.org/logging/guide.html#Configuration)

1

Bạn có thể làm một cái gì đó như thế này:

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); 
+0

trình cho tôi. 1 để bao gồm tên lớp học đầy đủ. – Ags1

7

Điều này có thể muộn, nhưng trong phiên bản 1.1, bạn có thể tạo một lớp thực hiện EventListener. Trong processEvent, bạn có thể bỏ qua bất kỳ tin nhắn nào bạn không muốn xem.

Từ 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; 
     } 
    } 
} 

Cách sử dụng:

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()); 
Các vấn đề liên quan