mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-25 02:21:28 +01:00
updated logging configuration
Former-commit-id: 7e4b433ae693ce9a00663cdd0364aa54c31bba1c
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -398,5 +398,11 @@ along with DependencyCheck. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--<dependency>
|
||||||
|
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -18,11 +18,16 @@ package org.codesecure.dependencycheck;
|
|||||||
* Copyright (c) 2012 Jeremy Long. All Rights Reserved.
|
* Copyright (c) 2012 Jeremy Long. All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.LogManager;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import org.apache.commons.cli.ParseException;
|
import org.apache.commons.cli.ParseException;
|
||||||
import org.codesecure.dependencycheck.data.cpe.Index;
|
import org.codesecure.dependencycheck.data.cpe.Index;
|
||||||
@@ -57,29 +62,55 @@ import org.xml.sax.SAXException;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final String LOG_PROPERTIES_FILE = "configuration/log.properties";
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//Preferences.systemRoot().put("java.util.logging.config.file", "log.properties");
|
prepareLogger();
|
||||||
App app = new App();
|
App app = new App();
|
||||||
app.run(args);
|
app.run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void prepareLogger() {
|
||||||
|
//while java doc for JUL says to use preferences api - it throws an exception...
|
||||||
|
//Preferences.systemRoot().put("java.util.logging.config.file", "log.properties");
|
||||||
|
//System.getProperties().put("java.util.logging.config.file", "configuration/log.properties");
|
||||||
|
File dir = new File("logs");
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkdir();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
InputStream in = App.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE);
|
||||||
|
LogManager.getLogManager().reset();
|
||||||
|
LogManager.getLogManager().readConfiguration(in);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println(ex.toString());
|
||||||
|
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
} catch (SecurityException ex) {
|
||||||
|
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main CLI entry-point into the application.
|
* main CLI entry-point into the application.
|
||||||
*
|
*
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
public void run(String[] args) {
|
public void run(String[] args) {
|
||||||
|
|
||||||
CliParser cli = new CliParser();
|
CliParser cli = new CliParser();
|
||||||
try {
|
try {
|
||||||
cli.parse(args);
|
cli.parse(args);
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
|
System.err.println(ex.getMessage());
|
||||||
|
cli.printHelp();
|
||||||
|
Logger.getLogger(App.class.getName()).log(Level.WARNING, null, ex);
|
||||||
return;
|
return;
|
||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
|
System.err.println(ex.getMessage());
|
||||||
|
cli.printHelp();
|
||||||
|
Logger.getLogger(App.class.getName()).log(Level.INFO, null, ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
public static final String CONNECTION_TIMEOUT = "connection.timeout";
|
public static final String CONNECTION_TIMEOUT = "connection.timeout";
|
||||||
}
|
}
|
||||||
private static final String PROPERTIES_FILE = "META-INF/dependencycheck.properties";
|
private static final String PROPERTIES_FILE = "configuration/dependencycheck.properties";
|
||||||
private static final Settings INSTANCE = new Settings();
|
private static final Settings INSTANCE = new Settings();
|
||||||
private Properties props = null;
|
private Properties props = null;
|
||||||
|
|
||||||
|
|||||||
21
src/main/resources/configuration/log.properties
Normal file
21
src/main/resources/configuration/log.properties
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
||||||
|
|
||||||
|
# logging levels
|
||||||
|
# FINEST, FINER, FINE, CONFIG, INFO, WARNING and SEVERE.
|
||||||
|
|
||||||
|
# Configure the ConsoleHandler.
|
||||||
|
java.util.logging.ConsoleHandler.level=SEVERE
|
||||||
|
|
||||||
|
# Configure the FileHandler.
|
||||||
|
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
|
||||||
|
java.util.logging.FileHandler.level=FINEST
|
||||||
|
|
||||||
|
# The following special tokens can be used in the pattern property
|
||||||
|
# which specifies the location and name of the log file.
|
||||||
|
# / - standard path separator
|
||||||
|
# %t - system temporary directory
|
||||||
|
# %h - value of the user.home system property
|
||||||
|
# %g - generation number for rotating logs
|
||||||
|
# %u - unique number to avoid conflicts
|
||||||
|
# FileHandler writes to %h/demo0.log by default.
|
||||||
|
java.util.logging.FileHandler.pattern=./logs/DependencyCheck%g.log
|
||||||
21
src/test/resources/log.properties
Normal file
21
src/test/resources/log.properties
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
||||||
|
|
||||||
|
# logging levels
|
||||||
|
# FINEST, FINER, FINE, CONFIG, INFO, WARNING and SEVERE.
|
||||||
|
|
||||||
|
# Configure the ConsoleHandler.
|
||||||
|
java.util.logging.ConsoleHandler.level=SEVERE
|
||||||
|
|
||||||
|
# Configure the FileHandler.
|
||||||
|
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
|
||||||
|
java.util.logging.FileHandler.level=FINEST
|
||||||
|
|
||||||
|
# The following special tokens can be used in the pattern property
|
||||||
|
# which specifies the location and name of the log file.
|
||||||
|
# / - standard path separator
|
||||||
|
# %t - system temporary directory
|
||||||
|
# %h - value of the user.home system property
|
||||||
|
# %g - generation number for rotating logs
|
||||||
|
# %u - unique number to avoid conflicts
|
||||||
|
# FileHandler writes to %h/demo0.log by default.
|
||||||
|
java.util.logging.FileHandler.pattern=./logs/DependencyCheck%g.log
|
||||||
Reference in New Issue
Block a user