Skip to content

Commit

Permalink
initialize log4j configuration only once
Browse files Browse the repository at this point in the history
initialize log4j configuration only once
  • Loading branch information
ashitsalesforce committed Oct 22, 2024
1 parent 9a7f4b6 commit fe4659a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/salesforce/dataloader/util/LoggingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ public class LoggingUtil {
private static final String LOG_CONF_DEFAULT_PROPERTIES = "log4j2.properties";
public static String LOG_CONF_DEFAULT = LOG_CONF_DEFAULT_PROPERTIES;
private static Logger logger;
private static boolean logInitialized = false;


public static synchronized void initializeLog(Map<String, String> argsMap) throws FactoryConfigurationError, IOException {
if (logInitialized) {
return;
}
// check the environment variable for log4j
String log4jConfigFilePath = System.getenv("LOG4J_CONFIGURATION_FILE");
if (log4jConfigFilePath == null || log4jConfigFilePath.isEmpty()) {
Expand Down Expand Up @@ -113,8 +117,9 @@ public static synchronized void initializeLog(Map<String, String> argsMap) throw

// this will force a reconfiguration
context.setConfigLocation(file.toURI());
logger = LogManager.getLogger(AppUtil.class);
logger.debug(Messages.getMessage(AppUtil.class, "logInit")); //$NON-NLS-1$
logger = LogManager.getLogger(LoggingUtil.class);
logger.debug(Messages.getMessage(LoggingUtil.class, "logInit")); //$NON-NLS-1$
logInitialized = true;
}

public static void setLoggingLevel(String newLevelStr) {
Expand Down

0 comments on commit fe4659a

Please sign in to comment.