set logging level com.openhtmlpdf to ERROR only

2.2k Views Asked by At

So I use openhtmltopdf library to render my HTML to pdf, every time it run it will show info log like below. Is there any way to set the logging level to only ERROR/SEVERE only

public File exportToPdfBox(Map<String, Object> variables, String templatePath, String out) {
    try (OutputStream os = new FileOutputStream(out);) {
        // There are more options on the builder than shown below.
        PdfRendererBuilder builder = new PdfRendererBuilder();
        builder.withHtmlContent(getHtmlString(variables, templatePath), "file:");
        builder.toStream(os);
        builder.run();
    } catch (Exception e) {
        log.error("Exception while generating pdf : {}", e);
    }
    return new File(out);
}

My stack trace

com.openhtmltopdf.load INFO:: SAX XMLReader in use (parser):com.sun.org.apache.xerces.internal.parsers.SAXParser
 com.openhtmltopdf.load INFO:: SAX XMLReader in use (parser):
 com.sun.org.apache.xerces.internal.parsers.SAXParser
 com.openhtmltopdf.load INFO:: Loaded document in ~43ms
 com.openhtmltopdf.load INFO:: TIME: parse stylesheets  200ms
 com.openhtmltopdf.match INFO:: media = print com.openhtmltopdf.match
 INFO:: Matcher created with 1180 selector

s

i try XRLog.setLevel() but it seems to not working, right now i only know XRLog.setLoggingEnabledcan turn off the log but I don't want to turn it off. I only want the ERROR log to show not the info. Thanks

1

There are 1 best solutions below

1
On

This worked for me in v1.0.4.

XRLog.listRegisteredLoggers().forEach(logger -> XRLog.setLevel(logger, java.util.logging.Level.OFF));

Details here: https://github.com/danfickle/openhtmltopdf/wiki/Logging