I am new to using the Tess4J library. I have included the Tess4j as a dependency in Maven like so:
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.5.1</version>
</dependency>
So far it has worked great, but I am unable to figure out how to disable the logging. It appears that the logs are coming from PDFBox and Fontbox which are dependencies of Tess4j. Here are some of the things that are being logged here:
19:54:46.712 [main] DEBUG org.apache.fontbox.util.autodetect.FontFileFinder - checkFontfile found C:\WINDOWS\FONTS\YuGothR.ttc
19:54:46.757 [main] DEBUG org.apache.pdfbox.pdmodel.font.FileSystemFontProvider - Loaded Arial-BoldMT from C:\WINDOWS\FONTS\arialbd.ttf
19:54:46.860 [main] DEBUG org.apache.pdfbox.pdmodel.font.FileSystemFontProvider - Loaded Arial-BoldItalicMT from C:\WINDOWS\FONTS\arialbi.ttf
19:54:46.899 [main] DEBUG org.apache.pdfbox.pdmodel.font.FileSystemFontProvider - Loaded ArialMT from C:\WINDOWS\FONTS\arial.ttf
19:54:46.955 [main] DEBUG org.apache.pdfbox.pdmodel.font.FileSystemFontProvider - Loaded Arial-ItalicMT from C:\WINDOWS\FONTS\ariali.ttf
19:54:47.477 [Finalizer] DEBUG org.apache.pdfbox.io.ScratchFileBuffer - ScratchFileBuffer not closed!
I tried setting the loging level before my code where I called for doOCR, but it still appears to be logging this information. Here is my code snippet:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Logger;
import net.sourceforge.tess4j.*;
public static void main(String[] args) throws TesseractException, FileNotFoundException, IOException {
Tesseract tesseract = getTesseract("C:\\Program Files\\Tesseract-OCR\\tessdata");
// My attempts to disable logging
Logger.getLogger("org.apache.fontbox").setLevel(java.util.logging.Level.OFF);
Logger.getLogger("org.apache.pdfbox").setLevel(java.util.logging.Level.OFF);
// Example 1
File file = new File("test.pdf");
String result = tesseract.doOCR(file);
System.out.println(result);
}
tess4j
library dependencies include logback.
Therefore I assume the logs are produced by logback, not by standard java logging (java.util.logging
package).
It means you should configure logback to disable unnecessary logging.
In maven projects it should be enough to create a file src/main/resources/logback.xml
with content like this:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.apache.fontbox" level="ERROR"/>
<logger name="org.apache.pdfbox" level="ERROR"/>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>