Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/patch'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidra1 committed Dec 17, 2021
2 parents 0d11cd0 + f97bcbc commit fe7585b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 49 deletions.
3 changes: 3 additions & 0 deletions Ghidra/Features/Base/build.gradle
Expand Up @@ -53,6 +53,9 @@ dependencies {

runtimeOnly "org.slf4j:slf4j-nop:1.7.25"

// use this if you want slf4j log messages sent to log4j
// runtimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:2.16.0"

compileOnly "junit:junit:4.12"

// These have abstract test classes and stubs needed by this module
Expand Down
8 changes: 0 additions & 8 deletions Ghidra/Features/GraphServices/build.gradle
Expand Up @@ -35,14 +35,6 @@ dependencies {
// not using jgrapht-io code that depends on antlr, so exclude antlr
api ("org.jgrapht:jgrapht-io:1.5.1") { exclude group: "org.antlr", module: "antlr4-runtime" }

runtimeOnly "org.slf4j:slf4j-api:1.7.25"

// use this if you want no slf4j log messages
runtimeOnly "org.slf4j:slf4j-nop:1.7.25"

// use this if you want slf4j log messages sent to log4j
// runtimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:2.16.0"

runtimeOnly "org.jheaps:jheaps:0.13"

helpPath project(path: ":Base", configuration: 'helpPath')
Expand Down
Expand Up @@ -28,7 +28,6 @@

public class LoggingInitialization {

private static final String LOG4J_CONFIGURATION_PROPERTY = "log4j.configuration";
private static final String LOG4J2_CONFIGURATION_PROPERTY = "log4j.configurationFile";

private static final String PRODUCTION_LOGGING_CONFIGURATION_FILE = "generic.log4j.xml";
Expand All @@ -44,35 +43,48 @@ public synchronized static void initializeLoggingSystem() {
return;
}

URL resource = getLoggingConfigFileUrl();
if (resource != null) {
try {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.setConfigLocation(resource.toURI());

// make future, unresolved contexts (e.g. from OSGi bundles) use this configuration
System.setProperty(LOG4J2_CONFIGURATION_PROPERTY, resource.toURI().toString());
}
catch (URISyntaxException e) {
Msg.error(LoggingInitialization.class, "Unable to convert URL to URI", e);
}
}
URL configFileUrl = installConfigFile();

Msg.setErrorLogger(new Log4jErrorLogger());
String configFilename =
(resource == null) ? "<no config file found>" : resource.toExternalForm();
(configFileUrl == null) ? "<no config file found>" : configFileUrl.toExternalForm();
Msg.info(LoggingInitialization.class, "Using log config file: " + configFilename);
Msg.info(LoggingInitialization.class, "Using log file: " + APPLICATION_LOG_FILE);
INITIALIZED = true;
}

private static URL installConfigFile() {
URL configFileUrl = getLoggingConfigFileUrl();
if (configFileUrl == null) {
return null;
}

try {

// Ensure this property is set. Some code paths set the property, but some do not.
System.setProperty(LOG4J2_CONFIGURATION_PROPERTY, configFileUrl.toURI().toString());

// force the log system to initialize
LogManager.getContext(false);
return configFileUrl;
}
catch (URISyntaxException e) {
Msg.error(LoggingInitialization.class, "Unable to convert URL to URI", e);
return null;
}
}

private static URL getLoggingConfigFileUrl() {
URL resource = getLogFileFromSystemProperty();
if (resource != null) {
return resource;
}

// no system property resource defined...use one of our defaults
return getDefaultLoggingConfigFileUrl();
}

private static URL getDefaultLoggingConfigFileUrl() {
String loggingConfigFilename = PRODUCTION_LOGGING_CONFIGURATION_FILE;
if (SystemUtilities.isInDevelopmentMode()) {
loggingConfigFilename = DEVELOPMENT_LOGGING_CONFIGURATION_FILE;
Expand All @@ -82,7 +94,7 @@ private static URL getLoggingConfigFileUrl() {
}

private static URL getLogFileFromSystemProperty() {
String configString = System.getProperty(LOG4J_CONFIGURATION_PROPERTY);
String configString = System.getProperty(LOG4J2_CONFIGURATION_PROPERTY);
if (configString == null) {
return null;
}
Expand All @@ -98,7 +110,6 @@ private static URL getLogFileFromSystemProperty() {
// maybe it is already in URL form: file://some/file/path
try {
URL url = new URL(configString);

File file = new File(url.toURI());
if (file.exists()) {
return url;
Expand All @@ -109,7 +120,7 @@ private static URL getLogFileFromSystemProperty() {
}

// we have to reset the property so that the DOMConfigurator does not use it
System.setProperty(LOG4J_CONFIGURATION_PROPERTY, "");
System.setProperty(LOG4J2_CONFIGURATION_PROPERTY, "");
System.err.println("Log config file does not exist: " + configString);
return null;
}
Expand All @@ -129,6 +140,7 @@ private static URL getLogFileFromSystemProperty() {

/**
* Returns the default file used for logging messages.
* @return the file
*/
public synchronized static File getApplicationLogFile() {
if (APPLICATION_LOG_FILE == null) {
Expand All @@ -141,8 +153,8 @@ public synchronized static File getApplicationLogFile() {
}

/**
* Use this to override the default application log file, before you
* initialize the logging system.
* Use this to override the default application log file, before you initialize the logging
* system.
*
* @param file The file to use as the application log file
*/
Expand All @@ -156,9 +168,9 @@ synchronized static void setApplicationLogFile(File file) {
}
APPLICATION_LOG_FILE = file;

// Need to set the system property that the log4j2 configuration reads in
// order to determine the log file name. Once that's set, the log
// configuration must be 'kicked' to pick up the change.
// Need to set the system property that the log4j2 configuration reads in order to
// determine the log file name. Once that's set, the log configuration must be 'kicked' to
// pick up the change.
System.setProperty("logFilename", file.getAbsolutePath());
if (INITIALIZED) {
((LoggerContext) LogManager.getContext(false)).reconfigure();
Expand All @@ -167,6 +179,7 @@ synchronized static void setApplicationLogFile(File file) {

/**
* Returns the default file used for logging messages.
* @return the file
*/
public synchronized static File getScriptLogFile() {
if (SCRIPT_LOG_FILE == null) {
Expand All @@ -192,9 +205,9 @@ synchronized static void setScriptLogFile(File file) {
}
SCRIPT_LOG_FILE = file;

// Need to set the system property that the log4j2 configuration reads in
// order to determine the script log file name. Once that's set, the log
// configuration must be 'kicked' to pick up the change.
// Need to set the system property that the log4j2 configuration reads in order to
// determine the script log file name. Once that's set, the log configuration must be
// 'kicked' to pick up the change.
System.setProperty("scriptLogFilename", file.getAbsolutePath());

if (INITIALIZED) {
Expand Down
15 changes: 0 additions & 15 deletions Ghidra/Framework/Generic/src/main/resources/log4j2.xml

This file was deleted.

0 comments on commit fe7585b

Please sign in to comment.