Skip to content

Commit

Permalink
ftr: add property to enable eager closing of log file
Browse files Browse the repository at this point in the history
  • Loading branch information
alxflam-work committed Oct 20, 2023
1 parent a1a4553 commit 739d4d3
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class EquinoxLogWriter implements SynchronousLogListener, LogFilter {

/** The system property used to specify command line args should be omitted from the log */
private static final String PROP_LOG_INCLUDE_COMMAND_LINE = "eclipse.log.include.commandline"; //$NON-NLS-1$
/** The system property used to specify the the log file writer should be closed eagerly */
private static final String PROP_CLOSE_LOG_FILE_EAGERLY = "eclipse.log.closeFile.eagerClose"; //$NON-NLS-1$

/** Indicates if the console messages should be printed to the console (System.out) */
private boolean consoleLog = false;
/** Indicates if the next log message is part of a new session */
Expand Down Expand Up @@ -112,6 +115,15 @@ class EquinoxLogWriter implements SynchronousLogListener, LogFilter {

private LoggerAdmin loggerAdmin = null;

/**
* Controls whether the log file should be closed eagerly upon every log
* invocation.
*
* Can be controlled by property
* {@link EquinoxLogWriter#PROP_CLOSE_LOG_FILE_EAGERLY}.
*/
private boolean closeLogFileEagerly = false;

/**
* Constructs an EclipseLog which uses the specified File to log messages to
* @param outFile a file to log messages to
Expand Down Expand Up @@ -322,6 +334,10 @@ private synchronized void log(FrameworkLogEntry logEntry) {
// ensure that the error stream writer is closed
closeFile();
}
} finally {
if (closeLogFileEagerly) {
closeFile();
}
}
}

Expand Down Expand Up @@ -683,6 +699,13 @@ else if (newLogLevel.equals("INFO")) //$NON-NLS-1$

includeCommandLine = "true".equals(environmentInfo.getConfiguration(PROP_LOG_INCLUDE_COMMAND_LINE, "true")); //$NON-NLS-1$//$NON-NLS-2$
applyLogLevel();

String newCloseLogFileEagerlyValue = environmentInfo.getConfiguration(PROP_CLOSE_LOG_FILE_EAGERLY);
if (newCloseLogFileEagerlyValue != null) {
if (Boolean.valueOf(newCloseLogFileEagerlyValue) == Boolean.TRUE) {
closeLogFileEagerly = true;
}
}
}

void applyLogLevel() {
Expand Down

0 comments on commit 739d4d3

Please sign in to comment.