Now switched to slf4j

Former-commit-id: 880512e5998d86026cfec40b1a8a165dd6b4b8e1
This commit is contained in:
Will Stranathan
2015-06-16 18:50:05 -04:00
parent 1b4cb1379a
commit 8aca739f54
74 changed files with 1718 additions and 818 deletions

View File

@@ -17,6 +17,9 @@
*/
package org.owasp.dependencycheck.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -24,8 +27,6 @@ import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Includes methods to generate the MD5 and SHA1 checksum.
@@ -38,7 +39,7 @@ public final class Checksum {
/**
* The logger.
*/
private static final Logger LOGGER = Logger.getLogger(Checksum.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(Checksum.class);
/**
* Private constructor for a utility class.
@@ -89,7 +90,7 @@ public final class Checksum {
try {
fis.close();
} catch (IOException ex) {
LOGGER.log(Level.FINEST, "Error closing file '" + file.getName() + "'.", ex);
LOGGER.trace("Error closing file '{}'.", file.getName(), ex);
}
}
}

View File

@@ -17,6 +17,9 @@
*/
package org.owasp.dependencycheck.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -26,8 +29,6 @@ import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.InvalidAlgorithmParameterException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
import java.util.zip.InflaterInputStream;
@@ -41,7 +42,7 @@ public final class Downloader {
/**
* The logger.
*/
private static final Logger LOGGER = Logger.getLogger(Downloader.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(Downloader.class);
/**
* The maximum number of redirects that will be followed when attempting to download a file.
*/
@@ -95,7 +96,7 @@ public final class Downloader {
} else {
HttpURLConnection conn = null;
try {
LOGGER.fine(String.format("Attempting download of %s", url.toString()));
LOGGER.debug("Attempting download of {}", url.toString());
conn = URLConnectionFactory.createHttpURLConnection(url, useProxy);
conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
conn.connect();
@@ -111,7 +112,7 @@ public final class Downloader {
} finally {
conn = null;
}
LOGGER.fine(String.format("Download is being redirected from %s to %s", url.toString(), location));
LOGGER.debug("Download is being redirected from {} to {}", url.toString(), location);
conn = URLConnectionFactory.createHttpURLConnection(new URL(location), useProxy);
conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
conn.connect();
@@ -157,7 +158,7 @@ public final class Downloader {
while ((bytesRead = reader.read(buffer)) > 0) {
writer.write(buffer, 0, bytesRead);
}
LOGGER.fine(String.format("Download of %s complete", url.toString()));
LOGGER.debug("Download of {} complete", url.toString());
} catch (IOException ex) {
analyzeException(ex);
final String msg = String.format("Error saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
@@ -172,14 +173,14 @@ public final class Downloader {
try {
writer.close();
} catch (IOException ex) {
LOGGER.log(Level.FINEST, "Error closing the writer in Downloader.", ex);
LOGGER.trace("Error closing the writer in Downloader.", ex);
}
}
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
LOGGER.log(Level.FINEST, "Error closing the reader in Downloader.", ex);
LOGGER.trace("Error closing the reader in Downloader.", ex);
}
}
try {
@@ -258,8 +259,8 @@ public final class Downloader {
LOGGER.info("Error making HTTPS request - InvalidAlgorithmParameterException");
LOGGER.info("There appears to be an issue with the installation of Java and the cacerts."
+ "See closed issue #177 here: https://github.com/jeremylong/DependencyCheck/issues/177");
LOGGER.info(String.format("Java Info:%njavax.net.ssl.keyStore='%s'%njava.version='%s'%njava.vendor='%s'",
keystore, version, vendor));
LOGGER.info("Java Info:\njavax.net.ssl.keyStore='{}'\njava.version='{}'\njava.vendor='{}'",
keystore, version, vendor);
throw new DownloadFailedException("Error making HTTPS request. Please see the log for more details.");
}
cause = cause.getCause();

View File

@@ -17,13 +17,14 @@
*/
package org.owasp.dependencycheck.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A collection of utilities for processing information about files.
@@ -35,7 +36,7 @@ public final class FileUtils {
/**
* The logger.
*/
private static final Logger LOGGER = Logger.getLogger(FileUtils.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
/**
* Bit bucket for non-Windows systems
*/
@@ -77,8 +78,7 @@ public final class FileUtils {
boolean success = true;
if (!org.apache.commons.io.FileUtils.deleteQuietly(file)) {
success = false;
final String msg = String.format("Failed to delete file: %s; attempting to delete on exit.", file.getPath());
LOGGER.log(Level.INFO, msg);
LOGGER.info("Failed to delete file: {}; attempting to delete on exit.", file.getPath());
file.deleteOnExit();
}
return success;

View File

@@ -17,6 +17,9 @@
*/
package org.owasp.dependencycheck.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -28,8 +31,6 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A simple settings container that wraps the dependencycheck.properties file.
@@ -264,7 +265,7 @@ public final class Settings {
/**
* The logger.
*/
private static final Logger LOGGER = Logger.getLogger(Settings.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(Settings.class);
/**
* The properties file location.
*/
@@ -290,14 +291,14 @@ public final class Settings {
in = this.getClass().getClassLoader().getResourceAsStream(propertiesFilePath);
props.load(in);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load default settings.");
LOGGER.log(Level.FINE, null, ex);
LOGGER.error("Unable to load default settings.");
LOGGER.debug("", ex);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
LOGGER.log(Level.FINEST, null, ex);
LOGGER.trace("", ex);
}
}
}
@@ -342,7 +343,7 @@ public final class Settings {
try {
localSettings.remove();
} catch (Throwable ex) {
LOGGER.log(Level.FINE, "Error cleaning up Settings", ex);
LOGGER.debug("Error cleaning up Settings", ex);
}
}
@@ -371,7 +372,7 @@ public final class Settings {
* @param properties the properties to log
*/
private static void logProperties(String header, Properties properties) {
if (LOGGER.isLoggable(Level.FINE)) {
if (LOGGER.isDebugEnabled()) {
final StringWriter sw = new StringWriter();
PrintWriter pw = null;
try {
@@ -390,7 +391,7 @@ public final class Settings {
}
}
pw.flush();
LOGGER.fine(sw.toString());
LOGGER.debug(sw.toString());
} finally {
if (pw != null) {
pw.close();
@@ -408,9 +409,7 @@ public final class Settings {
*/
public static void setString(String key, String value) {
localSettings.get().props.setProperty(key, value);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.format("Setting: %s='%s'", key, value));
}
LOGGER.debug("Setting: {}='{}'", key, value);
}
/**
@@ -425,9 +424,7 @@ public final class Settings {
} else {
localSettings.get().props.setProperty(key, Boolean.FALSE.toString());
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.format("Setting: %s='%b'", key, value));
}
LOGGER.debug("Setting: {}='{}'", key, value);
}
/**
@@ -449,7 +446,7 @@ public final class Settings {
try {
fis.close();
} catch (IOException ex) {
LOGGER.log(Level.FINEST, "close error", ex);
LOGGER.trace("close error", ex);
}
}
}
@@ -474,7 +471,7 @@ public final class Settings {
try {
fis.close();
} catch (IOException ex) {
LOGGER.log(Level.FINEST, "close error", ex);
LOGGER.trace("close error", ex);
}
}
}
@@ -523,16 +520,16 @@ public final class Settings {
*/
protected static File getDataFile(String key) {
final String file = getString(key);
LOGGER.log(Level.FINE, String.format("Settings.getDataFile() - file: '%s'", file));
LOGGER.debug("Settings.getDataFile() - file: '{}'", file);
if (file == null) {
return null;
}
if (file.startsWith("[JAR]")) {
LOGGER.log(Level.FINE, "Settings.getDataFile() - transforming filename");
LOGGER.debug("Settings.getDataFile() - transforming filename");
final File jarPath = getJarPath();
LOGGER.log(Level.FINE, String.format("Settings.getDataFile() - jar file: '%s'", jarPath.toString()));
LOGGER.debug("Settings.getDataFile() - jar file: '{}'", jarPath.toString());
final File retVal = new File(jarPath, file.substring(6));
LOGGER.log(Level.FINE, String.format("Settings.getDataFile() - returning: '%s'", retVal.toString()));
LOGGER.debug("Settings.getDataFile() - returning: '{}'", retVal.toString());
return retVal;
}
return new File(file);
@@ -549,7 +546,7 @@ public final class Settings {
try {
decodedPath = URLDecoder.decode(jarPath, "UTF-8");
} catch (UnsupportedEncodingException ex) {
LOGGER.log(Level.FINEST, null, ex);
LOGGER.trace("", ex);
}
final File path = new File(decodedPath);
@@ -652,8 +649,7 @@ public final class Settings {
try {
value = Integer.parseInt(Settings.getString(key));
} catch (NumberFormatException ex) {
final String msg = String.format("Could not convert property '%s' to an int.", key);
LOGGER.log(Level.FINEST, msg, ex);
LOGGER.trace("Could not convert property '{}' to an int.", key, ex);
value = defaultValue;
}
return value;
@@ -770,7 +766,7 @@ public final class Settings {
// yes, for H2 this path won't actually exists - but this is sufficient to get the value needed
final File dbFile = new File(directory, fileName);
final String cString = String.format(connStr, dbFile.getCanonicalPath());
LOGGER.log(Level.FINE, String.format("Connection String: '%s'", cString));
LOGGER.debug("Connection String: '{}'", cString);
return cString;
}
return connStr;