Skip to content

Commit

Permalink
Enable console logging when '-consolelog' is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed May 1, 2023
1 parent a083b3e commit ddbd9fb
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
Expand Down Expand Up @@ -56,6 +57,9 @@ public class M2ELogbackConfigurator extends BasicConfigurator implements Configu
// This has to match the log directory in defaultLogbackConfiguration/logback.xml
private static final String PROPERTY_LOG_DIRECTORY = "org.eclipse.m2e.log.dir"; //$NON-NLS-1$

// This has to match the log directory in defaultLogbackConfiguration/logback.xml
private static final String PROPERTY_LOG_CONSOLE_THRESHOLD = "org.eclipse.m2e.log.console.threshold"; //$NON-NLS-1$

@Override
public void configure(LoggerContext lc) {
// Bug 337167: Configuring Logback requires the state-location. If not yet initialized it will be initialized to the default value,
Expand Down Expand Up @@ -89,6 +93,11 @@ private synchronized void configureLogback(LoggerContext lc) {
if(System.getProperty(PROPERTY_LOG_DIRECTORY, "").length() <= 0) { //$NON-NLS-1$
System.setProperty(PROPERTY_LOG_DIRECTORY, stateDir.toAbsolutePath().toString());
}
if(System.getProperty(PROPERTY_LOG_CONSOLE_THRESHOLD, "").length() <= 0) { //$NON-NLS-1$
if(Arrays.stream(Platform.getCommandLineArgs()).filter(s -> s.equals("-consolelog")).findAny().isPresent()) {
System.setProperty(PROPERTY_LOG_CONSOLE_THRESHOLD, Level.DEBUG.levelStr);
}
}
loadConfiguration(lc, configFile.toUri().toURL());

//Delete old logs in legacy logback plug-in's state location. Can sum up to 1GB of disk-space.
Expand Down

0 comments on commit ddbd9fb

Please sign in to comment.