Skip to content

Commit

Permalink
Merge pull request #124 from datalogics-kam/dlpjts-129-logging
Browse files Browse the repository at this point in the history
DLPJTS-129 Use slf4j and log4j for logging.
  • Loading branch information
datalogics-coreyy authored Oct 10, 2017
2 parents c4ee065 + ae576eb commit 8d13af1
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fabric.properties
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
*.iml
# modules.xml
# .idea/misc.xml
# *.ipr
Expand Down
25 changes: 22 additions & 3 deletions lite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<checkstyle-config.version>2.0.2-SNAPSHOT</checkstyle-config.version>
<pmdconfig.version>2.0.0-SNAPSHOT</pmdconfig.version>
<pmdVersion>5.5.2</pmdVersion>
<pmdVersion>5.8.1</pmdVersion>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -110,6 +110,23 @@
<version>3.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down Expand Up @@ -278,7 +295,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<version>3.8</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -363,7 +380,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.14</version>
<version>1.16</version>
<executions>
<execution>
<id>check-java-version</id>
Expand Down Expand Up @@ -570,6 +587,8 @@
<include>.settings/org.eclipse.m2e.core.prefs</include>
<!-- all the Markdown files at the top level -->
<include>*.md</include>
<!-- log4j2 configuration files -->
<include>src/**/log4j2*.xml</include>
<!-- things used to build the project -->
<include>fix_throws_javadoc.sed</include>
<include>fix_throws_javadoc.sh</include>
Expand Down
65 changes: 0 additions & 65 deletions pdf-java-toolkit-samples.iml

This file was deleted.

23 changes: 20 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<checkstyle-config.version>2.1.0-SNAPSHOT</checkstyle-config.version>
<pmdconfig.version>2.0.0-SNAPSHOT</pmdconfig.version>
<pmdVersion>5.5.2</pmdVersion>
<pmdVersion>5.8.1</pmdVersion>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -111,6 +111,23 @@
<version>3.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down Expand Up @@ -278,7 +295,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<version>3.8</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -382,7 +399,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.14</version>
<version>1.16</version>
<executions>
<execution>
<id>check-java-version</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@
import com.datalogics.pdf.samples.util.FontUtils;
import com.datalogics.pdf.samples.util.IoUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.MethodHandles;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This sample demonstrates how to extract text from a document. The text is extracted in reading order and then saved
* to a text file.
*/
public final class TextExtract {
private static final Logger LOGGER = Logger.getLogger(TextExtract.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public static final String INPUT_PDF_PATH = "/com/datalogics/pdf/samples/pdfjavatoolkit-ds.pdf";
public static final String OUTPUT_TEXT_PATH = "TextExtract.txt";
Expand Down Expand Up @@ -105,7 +107,7 @@ public static void extractTextReadingOrder(final URL inputUrl, final URL outputU
} while (wordsIter.hasNext());
}
} else {
if (LOGGER.isLoggable(Level.INFO)) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(inputUrl.toURI().getPath() + " did not have any text to extract.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.invoke.MethodHandles;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This sample demonstrates exporting data from PDF form fields with formatting to a CSV file.
Expand All @@ -37,7 +38,7 @@ public final class ExportFormDataToCsv {
public static final String DEFAULT_INPUT = "filled_acroform.pdf";
public static final String CSV_OUTPUT = "exported-form-data.csv";

private static final Logger LOGGER = Logger.getLogger(ExportFormDataToCsv.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

/**
* This is a utility class, and won't be instantiated.
Expand Down Expand Up @@ -160,17 +161,17 @@ private static void exportFieldValues(final PDFInteractiveForm form, final CSVPr
final List<?> value = field.getValueList();
if (value == null) {
printer.print("");
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(field.getQualifiedName() + " has no value!");
if (LOGGER.isWarnEnabled()) {
LOGGER.warn(field.getQualifiedName() + " has no value!");
}
} else {
// If the list of values is not empty, write out only the first one.
// For more complex forms, the field type should be inspected to
// determine how to handle extracting the values.
printer.print(value.get(0).toString());
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(field.getQualifiedName()
+ " has no formatting rules! Writing out non formatted value!");
if (LOGGER.isWarnEnabled()) {
LOGGER.warn(field.getQualifiedName()
+ " has no formatting rules! Writing out non formatted value!");
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import com.datalogics.pdf.samples.util.DocumentUtils;
import com.datalogics.pdf.samples.util.IoUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.util.logging.Logger;


/**
Expand All @@ -44,7 +47,7 @@
*/

public final class ConvertPdfDocument {
private static final Logger LOGGER = Logger.getLogger(ConvertPdfDocument.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public static final String INPUT_UNCONVERTED_PDF_PATH = "UnConvertedPdf.pdf";
public static final String OUTPUT_CONVERTED_PDF_PATH = "ConvertedPdfa-1b.pdf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@
import com.datalogics.pdf.samples.util.DocumentUtils;
import com.datalogics.pdf.samples.util.IoUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.util.logging.Logger;

/**
* This sample demonstrates how to convert a PDF to a PDF/A-2 archive file. (PDF/A-2b by default)
*/
public final class ConvertToPdfA2 {
private static final Logger LOGGER = Logger.getLogger(ConvertToPdfA2.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public static final String INPUT_PDF_PATH = "UnconvertedPdfA2.pdf";
public static final String OUTPUT_PDF_PATH = "ConvertedToPdfA2.pdf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@
import com.datalogics.pdf.samples.util.DocumentUtils;
import com.datalogics.pdf.samples.util.IoUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.util.EnumSet;
import java.util.Locale;
import java.util.logging.Logger;

/**
* This sample demonstrates how to open a document, add redaction annotations to it, and then apply the redaction. The
Expand Down Expand Up @@ -95,7 +98,7 @@
* </ul>
*/
public final class RedactAndSanitizeDocument {
private static final Logger LOGGER = Logger.getLogger(RedactAndSanitizeDocument.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public static final String SEARCH_PDF_STRING = "Reader";
public static final String INPUT_PDF_PATH = "pdfjavatoolkit-ds.pdf";
Expand Down Expand Up @@ -314,7 +317,7 @@ public static void sanitizeDocument(final PDFDocument document, final URL saniti
PDFConfigurationException, PDFInvalidParameterException, PDFUnableToCompleteOperationException {

if (!canSanitizeDocument(document)) {
LOGGER.warning("The document was not sanitized");
LOGGER.warn("The document was not sanitized");
return;
}
ByteWriter writer = null;
Expand Down
Loading

0 comments on commit 8d13af1

Please sign in to comment.