public static HeadlessAnalyzer getLoggableInstance(File logFile, File scriptLogFile,
			boolean useLog4j) throws IllegalStateException, IOException {

		// Prevent more than one headless analyzer from being instantiated.  Too much about it
		// messes with global system settings, so under the current design of Ghidra, allowing
		// more than one to exist could result in unpredictable behavior.
		if (instance != null) {
			throw new IllegalStateException(
				"A headless analzyer instance has already been retrieved.  " +
					"Use HeadlessAnalyzer.getInstance() to get it.");
		}

		// Cannot set logging because application has already been initialized.
		if (Application.isInitialized()) {
			throw new IllegalStateException(
				"Logging cannot be set because the application has already been initialized.  " +
					"Use HeadlessAnalyzer.getInstance() to get the headless analyzer.");
		}

		// Initialize application with the provided logging parameters
		ApplicationConfiguration configuration = new HeadlessGhidraApplicationConfiguration();
		if (useLog4j) {
			if (logFile != null) {
				configuration.setApplicationLogFile(logFile);
			}
			if (scriptLogFile != null) {
				configuration.setScriptLogFile(scriptLogFile);
			}
		}
		else {
			configuration.setInitializeLogging(false);
			Msg.setErrorLogger(new HeadlessErrorLogger(logFile));
		}
		Application.initializeApplication(getApplicationLayout(), configuration);

		// Instantiate and return singleton headless analyzer
		instance = new HeadlessAnalyzer();
		return instance;
	}
Gets a headless analyzer, initializing the application if necessary with the specified
logging parameters.  An {@link IllegalStateException} will be thrown if the application has
already been initialized or a headless analyzer has already been retrieved.  In these cases,
the headless analyzer should be gotten with {@link HeadlessAnalyzer#getInstance()}.

@param logFile The desired application log file.  If null, the default application log file
  will be used (see {@link Application#initializeLogging}).
@param scriptLogFile The desired scripting log file.  If null, the default scripting log file
  will be used (see {@link Application#initializeLogging}).
@param useLog4j true if log4j is to be used; otherwise, false.  If this class is being used by
    another tool as a library, using log4j might interfere with that tool.
@return An instance of a new headless analyzer.
@throws IllegalStateException if an application or headless analyzer instance has already been initialized.
@throws IOException if there was a problem reading the application.properties file.
Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java